Bonsoir,
Tu peux aussi t'essayer aux expressions régulières.
Ainsi ta fonction , Sub serait courte et rapide comme suit :
Shared Sub changecouleur(ByVal rtb As RichTextBox, ByVal chaineatrouver AsString, ByVal Lcolor As Color)
Dim reCherchText As Regex = New Regex("[\s\r\n]*" & chaineatrouver)
Dim mReCherchText As Match = reCherchText.Match(rtb.Text)
Dim mcReCherchText As MatchCollection = reCherchText.Matches(rtb.Text)
With rtb
For Each mReCherchText In mcReCherchText
.Select(mReCherchText.Index, mReCherchText.Length)
.SelectionColor = Lcolor
Next
End With
End Sub
Sans oublier d'importer l'espace de nom :
Imports System.Text.RegularExpressions
« reCherchText » est la chaîne à coloriser, on y ajoute un ou plusieurs
espaces, retours chariot ou nouvelles lignes qui peuvent exister dans
ton expression à rechercher.
« Match » est la recherche cas par cas dans le texte.
« MatchColletion » regroupe l'ensemble des occurances trouvées.
Enfin la boucle parcourre ces occurances et les met en couleur.
Bonne continuation.