tt = "ababacdb"
debug.print instr(tt,"b") - 返回数为2要是只返回第3个b
debug.print instr(5,tt,"b")是不是要通过编程来解决?谢谢

解决方案 »

  1.   

    InStrRev函数
          描述返回一个字符串在另一个字符串中出现的位置,从字符串的末尾算起。
      

  2.   


    Public Function InStrEx(ByVal Source As String, ByVal Find As String, ByVal Place As Long) As Long    Dim lngCount As Long
        Dim lngLen   As Long
        
        lngLen = Len(Source)
        Do
            If lngCount = Place Then Exit Do
            lngCount = lngCount + 1
            Source = Right$(Source, Len(Source) - InStr(1, Source, Find) - Len(Find) + 1)
        Loop
        InStrEx = lngLen - Len(Source) - Len(Find) + 1End Function以前写的东西,不知道能用否?
      

  3.   

    调整InStr的第一个参数就可以了,不需要Right来取子串
      

  4.   


    通常循环+instr比较高效,如果字符串不大,也有取巧的方法:
    function GetValue(byval s as string,f as string,n as long) as long
        's源字符串,f要查找的字符串,n要找第几个f的位置
        GetValue=instr(replace(s,f,"x",,n-1),f)
    end function'应用:    dim tt as string
        tt = "ababacdb"
        Debug.Print GetValue(tt, "b", 3)
      

  5.   

    function GetValue(byval s as string,f as string,n as long) as long
        's源字符串,f要查找的字符串,n要找第几个f的位置
        GetValue=instr(replace(s,f,"x",,n-1),f)
    end function'应用:    dim tt as string
        tt = "ababacdb"
        Debug.Print GetValue(tt, "b", 3)
    这个方法比较简单实用.谢谢,vbman2003