假如这样一个字符串:str = e:/a/zzz/b/b/b.xls
我要截取从zzz开始一直到最后的部分;
但是str 这个字符串是变化的,其中只有zzz固定,其它的部分均不固定的,我要怎么写呢。

解决方案 »

  1.   

    补充一下:“其中只有zzz固定”是指str中肯定包含zzz,其它的都不一定包含
      

  2.   

    这样设想一下:
    第一,先用函数得到str中zzz的位置,
    第二,从zzz的起始开始截取自zzz往后的字符串
      

  3.   

    但是instr()函数只能得到单个字符的位置,我的这个zzz不是单个字符,有什么可用的函数吗
      

  4.   

    Private Sub Command1_Click()
        
        Dim i       As Long
        Dim strFind As String
        Dim strData As String
        
        strFind = "zzz"
        strData = "e:/a/zzz/b/b/b.xls"
        
        i = InStr(1, strData, strFind, vbTextCompare)
        
        If i > 0 Then
            Debug.Print Mid(strData, i + Len(strFind))
        End If
        
    End SubPrivate Sub Command2_Click()
        
        Dim v       As Variant
        Dim strFind As String
        Dim strData As String
        
        strFind = "zzz"
        strData = "e:/a/zzz/b/b/b.xls"
        
        v = Split(strData, strFind)
        
        If UBound(v) = 1 Then
            Debug.Print v(1)
        End If
        
    End Sub其中,第二种方法要求字符串中只能出现一次分隔字符。