有一文本内容如下:
UIName=aaa
Name=bbb
Tname=ccc
TnameA=ddd现在要搜索各行并选中,搜索关键字为=前的内容,问题是当关键字为name时只能搜到UIname当中的name
请问如何解决,敬盼答复,感谢非常
UIName=aaa
Name=bbb
Tname=ccc
TnameA=ddd现在要搜索各行并选中,搜索关键字为=前的内容,问题是当关键字为name时只能搜到UIname当中的name
请问如何解决,敬盼答复,感谢非常
p = 1
Do While p <> 0
p = RichTextBox1.Find("Name", p, , 8)
If p > 0 Then
RichTextBox1.SelStart = p
RichTextBox1.SelLength = 4
RichTextBox1.SelColor = vbRed
MsgBox p
End If
p = p + 1
Loop
End SubPrivate Sub Form_Load()
RichTextBox1.Text = "UIName=aaa " & vbCrLf & "Name=bbb " & vbCrLf & "Tname=ccc" & vbCrLf & "TnameA=ddd "End Sub
UIName=aaa
Name=bbb
Tname=ccc
TnameA=ddd
关键字为 = 前的内容 也就是 dim a as string,p as long
a="uiname"
p = RichTextBox1.Find(a)
'找到后选中 uiname=aaa 这里没问题'关键是下面这个
a="name"
p = RichTextBox1.Find(a)
'找到后选中 name=bbb 这里不行,他会选中 ui(name=aaa)a="tname"
p = RichTextBox1.Find(a)
'找到后选中 tname=ccc 这里也没问题以上问题不知是否表述清楚,还望各位不吝赐教,多多麻烦感激不尽
Dim b As Integer, p As Integer
b = 0
Do While b < 3
p = RichTextBox1.Find(A(b), 0)
If p > -1 Then
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SelColor = 0
RichTextBox1.SelStart = p
RichTextBox1.SelLength = Len(A(b))
RichTextBox1.SelColor = vbRed
MsgBox p
End If
b = b + 1
If b > 2 Then
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SelColor = 0
End If
Loop
End SubPrivate Sub Form_Load()
A(0) = "UIName"
A(1) = "Name"
A(2) = "Tname"
RichTextBox1.Text = "UIName=aaa " & vbCrLf & "Name=bbb " & vbCrLf & "Tname=ccc" & vbCrLf & "TnameA=ddd "
End Sub
主要使用instr函数,用法上网查查就知道了。。
p = 0
Do
p = RichTextBox1.Find(str, p, , 2)
If p > 0 Then
RichTextBox1.SelStart = p
RichTextBox1.SelLength = Len(str)
RichTextBox1.SelColor = vbRed
'MsgBox p
End If
p = p + 1
Loop Until p = 0
End SubPrivate Sub Command1_Click()
vFind "UIName"
vFind "Name"
vFind "Tname"
vFind "TnameA"
'装在数组里循环也行
End SubPrivate Sub Form_Load()
RichTextBox1.Text = vbCrLf & "UIName=aaa " & vbCrLf & "Name=bbb " & vbCrLf & "Tname=ccc" & vbCrLf & "TnameA=ddd "End Sub
richtextbox 如何快速的设置字体颜色呢?
问题是这样的,装入的文本很大,经过N多次查找后设置了很多颜色,现在需要吧所有颜色还原,整体选择在设置的话会比较慢
且会闪烁(可能需要多次还原),我现在的做法是每次查找操作前先重复上次的查找,设置还原颜色后在进行新的查找,
可是这样效率很低啊,所以我就想有没有比较好的方法,还望赐教一二,不胜感激。