Какой-то бред. s постоянно равно "Sub". Я в полном непонимании...
P.S. Отладка результатов не дала ((
Что это делает?
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FindAndMark(Rtb, "Private", "Public", "Sub", "End")
End Sub
Public Sub FindAndMark(ByVal rtb As RichTextBox, ByVal ParamArray sFind() As String)
Dim Rgx As Regex
If (sFind Is Nothing) Or (rtb.TextLength = 0) Then Return
Dim RegexPattern As String = "("
For Each s As String In sFind
RegexPattern &= s & "|"
Next
RegexPattern &= ")"
Rgx = New Regex(RegexPattern, RegexOptions.Multiline Or RegexOptions.IgnoreCase)
For Each M As Match In Rgx.Matches(rtb.Text)
rtb.SelectionStart = M.Index
rtb.SelectionLength = M.Length
rtb.SelectionColor = Color.Blue
Next
End Sub
End Class
Прикольно же будет выглядеть прцедура FindAndMark со всеми ключевыми словами
Вот попробовал -- виснет не по детски.
У меня например перекрашивается влет
Public Sub FindAndMark(ByVal sFind As String, ByVal rtb As RichTextBox)
Dim nLen As Integer = sFind.Length
Dim sText As String = rtb.Text
Dim nLenTxt As Integer = sText.Length
If nLen = 0 OrElse nLenTxt = 0 Then
Return
End If
Dim iPos As Integer = 1
Do
iPos = InStr(iPos, sText, sFind)
If iPos = 0 Then
Return
End If
With rtb
.SelectionStart = iPos - 1
.SelectionLength = nLen
.SelectionColor = Color.Red
.Focus()
End With
iPos += nLen
Loop
End Sub
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim StartTime As DateTime
'Замер производительности №1
StartTime = Now
FindAndMark(Rtb, "Public")
FindAndMark(Rtb, "Private")
MsgBox((Now - StartTime).TotalMilliseconds.ToString)
'Замер производительности №2
StartTime = Now
FindAndMarkWithRegex(Rtb, "Public")
FindAndMarkWithRegex(Rtb, "Private")
MsgBox((Now - StartTime).TotalMilliseconds.ToString)
End Sub
Public Sub FindAndMarkWithRegex(ByVal rtb As RichTextBox, ByVal sFind As String)
Dim M As Match
Dim MC As MatchCollection = Regex.Matches(rtb.Text, sFind, RegexOptions.IgnoreCase)
With rtb
For Each M In MC
.SelectionStart = M.Index
.SelectionLength = M.Length
.SelectionColor = Color.Blue
Next
End With
End Sub
Public Sub FindAndMark(ByVal rtb As RichTextBox, ByVal sFind As String)
Dim nLen As Integer = sFind.Length
Dim sText As String = rtb.Text
Dim nLenTxt As Integer = sText.Length
If nLen = 0 OrElse nLenTxt = 0 Then
Return
End If
Dim iPos As Integer = 1
Do
iPos = InStr(iPos, sText, sFind, CompareMethod.Text)
If iPos = 0 Then
Return
End If
With rtb
.SelectionStart = iPos - 1
.SelectionLength = nLen
.SelectionColor = Color.Red
'.Focus()
End With
iPos += nLen
Loop
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim FS As New IO.StreamReader("Текстовый документ.txt")
Rtb.Text = FS.ReadToEnd
MsgBox(Rtb.Lines.Length)
End Sub
End Class
Public Sub ХочуВсёЗнать()
Dim Doc As New IO.StreamReader("MSDN")
Мозги.Text = Doc.ReadToEnd
Мозги.Update
End Sub
Сейчас этот форум просматривают: AhrefsBot и гости: 48