Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been wrote this snippet time ago, it will teach you how to find and highlight word/phrases using Regular Expressions, you could easily adapt it to a WORD document reading, then the most important part of the problem would be solved with this:</p> <pre><code>#Region " [RichTextBox] FindNext RegEx " ' [ FindNext RegEx ] ' ' //By Elektro H@cker ' ' Examples : ' ' RichTextBox1.Text = "Hello World!, Hello World!, Hello World!" ' ' FindNext(RichTextBox1, "hello", FindDirection.Down, System.Text.RegularExpressions.RegexOptions.IgnoreCase, Color.LightBlue, Color.Black) ' FindNext(RichTextBox1, "hello", FindDirection.Up, System.Text.RegularExpressions.RegexOptions.IgnoreCase, Color.Red, Color.Black) ' ' Private Sub RichTextBox_Enter(sender As Object, e As EventArgs) ' Handles RichTextBox1.Enter ' ' Restore Selection Colors before search next match. ' sender.SelectionBackColor = DefaultBackColor ' sender.SelectionColor = DefaultForeColor ' End Sub Public Enum FindDirection As Short Up = 0 Down = 1 End Enum ' FindNext Private Sub FindNext(ByVal [Control] As RichTextBox, _ ByVal SearchText As String, _ ByVal Direction As FindDirection, _ Optional ByVal IgnoreCase As System.Text.RegularExpressions.RegexOptions = System.Text.RegularExpressions.RegexOptions.None, _ Optional ByVal Highlight_BackColor As Color = Nothing, _ Optional ByVal Highlight_ForeColor As Color = Nothing) If [Control].TextLength = 0 Then Exit Sub ' Start searching at 'SelectionStart'. Dim Search_StartIndex As Integer = [Control].SelectionStart ' Stores the MatchIndex count Dim matchIndex As Integer = 0 ' Flag to check if it's first find call Static First_Find As Boolean = True ' Checks to don't ommit the selection of first match if match index is exactly at 0 start point. If First_Find _ AndAlso Search_StartIndex = 0 _ AndAlso Direction = FindDirection.Down Then Search_StartIndex = -1 First_Find = False ElseIf Not First_Find _ AndAlso Search_StartIndex = 0 _ AndAlso Direction = FindDirection.Down Then First_Find = False Search_StartIndex = 0 End If ' Store the matches Dim matches As System.Text.RegularExpressions.MatchCollection = _ System.Text.RegularExpressions.Regex.Matches([Control].Text, _ SearchText, _ IgnoreCase Or If(Direction = FindDirection.Up, _ System.Text.RegularExpressions.RegexOptions.RightToLeft, _ System.Text.RegularExpressions.RegexOptions.None)) If matches.Count = 0 Then First_Find = True : Exit Sub ' Restore Highlight colors of previous selection [Control].SelectionBackColor = [Control].BackColor [Control].SelectionColor = [Control].ForeColor ' Set next selection Highlight colors If Highlight_BackColor = Nothing Then Highlight_BackColor = [Control].BackColor If Highlight_ForeColor = Nothing Then Highlight_ForeColor = [Control].ForeColor ' Set the match selection For Each match As System.Text.RegularExpressions.Match In matches matchIndex += 1 Select Case Direction Case FindDirection.Down If match.Index &gt; Search_StartIndex Then ' Select next match [Control].Select(match.Index, match.Length) Exit For ElseIf match.Index &lt;= Search_StartIndex _ AndAlso matchIndex = matches.Count Then ' Select first match [Control].Select(matches.Item(0).Index, matches.Item(0).Length) Exit For End If Case FindDirection.Up If match.Index &lt; Search_StartIndex Then ' Select previous match [Control].Select(match.Index, match.Length) Exit For ElseIf match.Index &gt;= Search_StartIndex _ AndAlso matchIndex = matches.Count Then ' Select last match [Control].Select(matches.Item(0).Index, matches.Item(0).Length) Exit For End If End Select Next match ' Set the current selection BackColor [Control].SelectionBackColor = Highlight_BackColor ' Set the current selection ForeColor [Control].SelectionColor = Highlight_ForeColor ' Scroll to Caret/Cursor selection position [Control].ScrollToCaret() End Sub #End Region </code></pre> <p>Also here you can see a video demostration: <a href="http://www.youtube.com/watch?v=mWRMdlC5DH8" rel="nofollow">http://www.youtube.com/watch?v=mWRMdlC5DH8</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload