aaaa,bbbb,cccc,eeee,ffff,gggg,hhhh,eeee,ffff,aaaa,kkkk,ccccc,去掉重复的
如:aaaa,bbbb,cccc,eeee,ffff,gggg,hhhh,kkkk,

解决方案 »

  1.   

    aaaa,bbbb,cccc,eeee,ffff,gggg,hhhh,eeee,ffff,aaaa,kkkk,ccccc,去掉重复的
    如:aaaa,bbbb,cccc,eeee,ffff,gggg,hhhh,kkkk,
    ===============================================================
    dim str as string
    dim str1 as string
    str="aaaa,bbbb,cccc,eeee,ffff,gggg,hhhh,eeee,ffff,aaaa,kkkk,ccccc"我这里没有VB开发环境,不好写代码我的思路是这样的,先用INSTR函数循环得到AAAA,BBBB,CCCC,EEEE等在长字符串里是不是有重复的
    再用REPLACE函数把有重复的去掉
      

  2.   

    Option Explicit'Powered by Jadeluo, 2005/05/23Private Function GetKeys(ByVal s As String) As String
        Dim t As String, i As Integer, r As String
        t = ""
        Do While s <> ""
            i = InStr(s, ",")
            If i > 0 Then
                r = Left(s, i - 1)
            Else
                r = s
            End If
            If t = "" Then
                t = t & r
            Else
                t = t & "," & r
            End If
            If Left(s, 1) <> "," Then s = "," & s
            If Right(s, 1) <> "," Then s = s & ","
            s = Mid(Replace(s, "," & r & ",", ","), 2)
        Loop
        GetKeys = t
    End FunctionPrivate Sub Form_Load()
        Debug.Print GetKeys("aaaa,bbbb,cccc,eeee,ffff,gggg,hhhh,eeee,ffff,aaaa,kkkk,ccccc")
        End
    End Sub
      

  3.   

    Dim arrTmp() As StringarrTmp=Split(str,",")'以","为分隔符,得到arrTmp数组
    然后再相互比较arrTmp中各元素,可以使用一种优先算法。
      

  4.   

    Option ExplicitPrivate Sub Command1_Click()
    Dim strOri As String
    Dim strResult As String
    Dim strOriArray() As String
    Dim strResultArray() As String
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim IsSame As Boolean
        strOri = "aaaa,bbbb,cccc,eeee,ffff,gggg,hhhh,eeee,ffff,aaaa,kkkk,ccccc"
        strOriArray() = Split(strOri, ",")
        ReDim strResultArray(UBound(strOriArray) + 1)
        For i = 0 To UBound(strOriArray)
            IsSame = False
            For j = 0 To k
                If strResultArray(j) = strOriArray(i) Then
                    IsSame = True
                    Exit For
                End If
            Next
            If Not IsSame Then
                k = k + 1
                strResultArray(k) = strOriArray(i)
            End If
        Next
        strResult = Join(strResultArray, "'")
                
    Print strResult
    End Sub
      

  5.   

    Function Rep(s, sp)
    Dim i As Integer, j As Integer, v, vs() As Boolean
    v = Split(s, sp)
    ReDim vs(UBound(v))
    For i = 0 To UBound(v)
        For j = i + 1 To UBound(v)
            If Not vs(j) Then vs(j) = (v(i) = v(j))
        Next j
    Next i
    For i = 0 To UBound(v)
        If Not vs(i) Then Rep = Rep & v(i) & sp
    Next i
    If InStr(1, Rep, sp) Then Rep = Left(Rep, Len(Rep) - 1)
    End Function
    end function
      

  6.   

    qqq001,qqq002,qqq003,qqq004,qqq007,qqq008,qqq019,qqq011,qqq005,qqq024,qqq006,qqq009,qqq010,qqq014,qqq015,qqq016,qqq002,qqq003,qqq004,qqq007,qqq008,qqq019,qqq001,qqq005,qqq009,qqq011,qqq010,qqq014,qqq015,qqq016,qqq002,qqq003,qqq004,qqq005,qqq012,qqq019,qqq001,qqq007,qqq008,qqq009,qqq010,qqq011,qqq014,qqq015,qqq016,qqq001,qqq002,qqq003,qqq004,qqq005,qqq006,qqq007,qqq008,qqq009,qqq010,qqq011,qqq012,qqq014,qqq013,qqq015,qqq016,qqq019,qqq002,qqq008,qqq011,qqq012,qqq013,qqq019,qqq001,qqq004,qqq005,qqq006,qqq007,qqq003,qqq009,qqq010,qqq014,qqq015,qqq016,qqq002,qqq008,qqq024,qqq001,qqq003,qqq004,qqq005,qqq006,qqq007,qqq009,qqq010,qqq011,qqq012,qqq013,qqq014,qqq015,qqq016,qqq019,qqq002,qqq005,qqq010,qqq012,qqq001,qqq003,qqq004,qqq006,qqq007,qqq008,qqq009,qqq011,qqq013,qqq014,qqq015,qqq016,qqq019,qqq001,qqq002,qqq003,qqq004,qqq005,qqq006,qqq007,qqq008,qqq009,qqq010,qqq011,qqq012,qqq013,qqq019,qqq014,qqq015,qqq016,qqq016,qqq001,qqq002,qqq003,qqq004,qqq005,qqq006,qqq007,qqq008,qqq009,qqq010,qqq011,qqq012,qqq013,qqq014,qqq015,qqq016,qqq019,qqq027,
      

  7.   

    修改一下就行了:Option Explicit'Powered by Jadeluo, 2005/05/24Private Function GetKeys(ByVal s As String) As String
        Dim t As String, i As Integer, r As String
        t = ""
        Do While s <> ""
            i = InStr(s, ",")
            If i > 0 Then
                r = Left(s, i - 1)
            Else
                r = s
            End If
            If t = "" Then
                t = t & r
            Else
                t = t & "," & r
            End If
            If Left(s, 1) <> "," Then s = "," & s
            s = Mid(Replace(s, "," & r, ""), 2)
        Loop
        GetKeys = t
    End FunctionPrivate Sub Form_Load()
        Dim s As String
        s = "qqq001,qqq002,qqq003,qqq004,qqq007,qqq008,qqq019,qqq011,qqq005,qqq024,qqq006,qqq009,qqq010,qqq014,qqq015,qqq016," & _
        "qqq002,qqq003,qqq004,qqq007,qqq008,qqq019,qqq001,qqq005,qqq009,qqq011,qqq010,qqq014,qqq015,qqq016,qqq002,qqq003,qqq004,qqq005,qqq012,qqq019,qqq001,qqq007,qqq008,qqq009,qqq010,qqq011,qqq014,qqq015,qqq016,qqq001,qqq002," & _
        "qqq003,qqq004,qqq005,qqq006,qqq007,qqq008,qqq009,qqq010,qqq011,qqq012,qqq014,qqq013,qqq015,qqq016,qqq019,qqq002,qqq008,qqq011,qqq012,qqq013,qqq019,qqq001,qqq004,qqq005,qqq006,qqq007,qqq003,qqq009,qqq010,qqq014,qqq015,qqq016," & _
        "qqq002,qqq008,qqq024,qqq001,qqq003,qqq004,qqq005,qqq006,qqq007,qqq009,qqq010,qqq011,qqq012,qqq013,qqq014,qqq015,qqq016,qqq019,qqq002,qqq005,qqq010,qqq012,qqq001,qqq003,qqq004,qqq006,qqq007,qqq008,qqq009,qqq011,qqq013,qqq014," & _
        "qqq015,qqq016,qqq019,qqq001,qqq002,qqq003,qqq004,qqq005,qqq006,qqq007,qqq008,qqq009,qqq010,qqq011,qqq012,qqq013,qqq019,qqq014,qqq015,qqq016,qqq016,qqq001,qqq002,qqq003,qqq004,qqq005,qqq006,qqq007,qqq008,qqq009,qqq010,qqq011," & _
        "qqq012,qqq013,qqq014,qqq015,qqq016,qqq019,qqq027,"
        Debug.Print GetKeys(s)
        End
    End Sub
      

  8.   

    用字符串Key,把他們放入Collection,然後再拿出來就可以了!
      

  9.   

    Option ExplicitPrivate Sub Command1_Click()
    Dim strOri As String
    Dim strResult As String
    Dim strOriArray() As String
    Dim strResultArray() As String
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim IsSame As Boolean
        strOri = Text1
        strOriArray() = Split(strOri, ",")
        ReDim strResultArray(UBound(strOriArray) + 1)
        For i = 0 To UBound(strOriArray)
            IsSame = False
            For j = 0 To k
                If strResultArray(j) = strOriArray(i) Then
                    IsSame = True
                    Exit For
                End If
            Next
            If Not IsSame Then
                k = k + 1
                strResultArray(k) = strOriArray(i)
            End If
        Next
        strResult = Join(strResultArray)
        strResult = Trim(strResult)
        strResult = Replace(strResult, " ", ",")
        Text2 = strResult
    End Sub
    结果为:
    qqq001,qqq002,qqq003,qqq004,qqq007,qqq008,qqq019,qqq011,qqq005,qqq024,qqq006,qqq009,qqq010,qqq014,qqq015,qqq016,qqq012,qqq013,qqq027