怎样求一个字符在另一字符串的位置,越简单越好

解决方案 »

  1.   

    如楼上的,instr(str,substr),你可以指定从什么地方搜索起(默认是从头开始)
      

  2.   

    dim str="abcdaabcef"
    dim c="a"
    dim CountNum as integerfor i=1 to len(str)
       if mid(str,i,1)=a then
          countnum=countnum+1
       end if
    next i
      

  3.   

    dim strTmp as string, str1, str2 as string
    dim n as longstr1 = "acbdbdad12d56d98cd"
    str2 = "d"
    n = len(str1)
    strTmp = replace(str1,str2,"")
    msgbox str1 & " 在 " & str2 & " 中出现 " & n - len(strTmp) & " 次"
      

  4.   

    dim str1 as string,str2
    str1 = "acbdbdad12d56d98cd"
    str2="d"
      MsgBox "d 在 " & str1 & " 中出现 " & UBound(Split(str1, "d")) & " 次"
      

  5.   

    Private Sub Command1_Click()
    Dim str As String
    str = "abcdaabcef"
    Dim c As String
    c = "1"
    Dim temp As Variant
    temp = Split(str, c)
    Dim i As Integer 'i 为所求
    i = UBound(temp)
    Print iEnd Sub