有一文本内容如下:
UIName=aaa
Name=bbb
Tname=ccc
TnameA=ddd现在要搜索各行并选中,搜索关键字为=前的内容,问题是当关键字为name时只能搜到UIname当中的name
请问如何解决,敬盼答复,感谢非常

解决方案 »

  1.   

    Private Sub Command1_Click()
    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
      

  2.   

    楼上的大哥,不对呀我要的是这样的 
    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  这里也没问题以上问题不知是否表述清楚,还望各位不吝赐教,多多麻烦感激不尽
      

  3.   

    我贴出我的代码Dim A(0 To 2)Private Sub Command1_Click()
    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
      

  4.   

    那很简单啊,不用正则表达式了,你循环查找vbCrLf,再从vbCrLf出发找=,判断两者之间的内容是不是你的关键字就行了,但第一个=号前没有vbCrLf 要做 些处理。
    主要使用instr函数,用法上网查查就知道了。。
      

  5.   

    Private Sub vFind(str As String)
    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
      

  6.   

    lsftest 的方法很好用,非常感谢。(我怎么就没想到呢?笨死了)再提个问题
    richtextbox 如何快速的设置字体颜色呢?
    问题是这样的,装入的文本很大,经过N多次查找后设置了很多颜色,现在需要吧所有颜色还原,整体选择在设置的话会比较慢
    且会闪烁(可能需要多次还原),我现在的做法是每次查找操作前先重复上次的查找,设置还原颜色后在进行新的查找,
    可是这样效率很低啊,所以我就想有没有比较好的方法,还望赐教一二,不胜感激。