我新做了一个记事本程序,只是可惜没有添加查找功能,有谁能告诉我怎样在记事本程序中添加查找功能,并且显示出查找字符的个数。我以高分相送。

解决方案 »

  1.   

    用Instr函数吧
    从字符串"AAAABBAAA"的第一个字符开始查找字符"BB"
    lPos=Instr(1,"AAAABBAAABBAA","BB")
    返回lPos=5
    再调用一次
    lPos=Instr(lPos+1,"AAAABBAAABBAA","BB")
    返回lPos=10
      

  2.   

    你在自动生成DIM窗体中看看(生成一个DIM窗体),这里面有查找和替换的选项,在里面参考一下。
      

  3.   

    你是用什么控件做的记事伯,如果是TEXT控件,则需要自己写函数了,如果是RICHTEXTBOX,则提供了查找函数,不过查找字符的个数还得自己算!!
      

  4.   

    private sub findTxt(byval cTxt as string,optional byval lStart as long=-1,optional byval bFromBegin as boolean=true,optional byval bIgnoorUL as boolean = true)
      dim I as long
      dim J as integer
      
      J=abs(cint(bIgnoorUL)
      if bFromBegin then
          if lStart=-1 then lStart=1
          i=instr(lStart,text1.text,ctxt,J)
      else
          
          i=instrrev(text1.text,ctxt,lStart,J)
      end if
      
      if i<1 then
        msgbox "找不到"
      else
        text1.selstart=I
        text1.sellength=len(ctxt)
      end if
    end sub
    没有调试,意思应该是这样的
      

  5.   

    To cuizm(射天狼):
      我用的是RICHTEXTBOX,请问查找函数到哪里去找?
      

  6.   

    这是MSDN的例子,看看能不能帮上忙吧!
    Public Function FindMyText(ByVal searchText As String, ByVal searchStart As Integer, ByVal searchEnd As Integer) As Integer
        ' Initialize the return value to false by default.
        Dim returnValue As Integer = -1    ' Ensure that a search string and a valid starting point are specified.
        If searchText.Length > 0 And searchStart >= 0 Then
            ' Ensure that a valid ending value is provided.
            If searchEnd > searchStart Or searchEnd = -1 Then
                ' Obtain the location of the search string in richTextBox1.
            Dim indexToText As Integer = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase)
                ' Determine whether the text was found in richTextBox1.
                If indexToText >= 0 Then
                    ' Return the index to the specified search text.
                    returnValue = indexToText
                End If
            End If
        End If