如字符串:11111/11111/aaaaa/33333/11111/aaaaa/以“/”为分界,提取不同的元素,结果如下:11111/aaaaa/33333/

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim s As String
        s = "11111/11111/aaaaa/33333/11111/aaaaa/"
        MsgBox test(s, "/")
    End SubPrivate Function test(ByVal s As String, splitstr As String) As String
        Dim mCollection As New Collection
        Dim buff() As String
        buff = Split(s, splitstr)
        Dim tmp() As String
        Dim i As Long
        Dim n As Long
        On Error Resume Next
        For i = 0 To UBound(buff)        
            mCollection.Add buff(i), buff(i)
        Next
        
        
        ReDim tmp(mCollection.Count - 1)
        For i = 0 To mCollection.Count - 1
            tmp(i) = mCollection.Item(i)        
         Next
         Set mCollection = Nothing
         test = Join(tmp, splitstr)
    End Function
      

  2.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim strText As Variant
        Dim strDif As String
            
        Dim I As Long
        Dim J As Long
        
        strText = Split("11111/11111/aaaaa/33333//11111/aaaaa/", "/")
        
        strDif = strText(0)
        
        For I = 1 To UBound(strText)
            If InStr(1, strDif, strText(I)) < 1 Then
                strDif = strDif & "/" & strText(I)
            End If
        Next
        
        Debug.Print strDif
        
    End Sub
      

  3.   

    to : rainstormmaster(暴风雨 v2.0) 非常感谢,但结果是/11111/aaaaa/33333可否改成11111/aaaaa/33333/?