现有一串字符串,要把重复的字符给去掉,怎么办?
例:字符串为"604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,"
得到的结果为"604134a,604134b,604134c,604134d,604134e"大侠们帮我写写个表达式!谢了

解决方案 »

  1.   

    Private function GetStr(byval strSource as string) as string
        Dim l_arrTmp() As String
        Dim I As Integer
        Dim J As Integer
        Dim l_strResult As String
        
        'l_arrTmp = Split ("604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,", ",")
         l_arrTmp = Split(strSource,",") 
        For I = 0 To UBound(l_arrTmp) - 1
            For J = I + 1 To UBound(l_arrTmp)
                If l_arrTmp(I) = l_arrTmp(J) Then
                    GoTo NextI
                End If
            Next J
            l_strResult = l_strResult & "," & l_arrTmp(I)
    NextI:
        Next I
        GetStr= Right(l_strResult, Len(l_strResult) - 1)
         msgbox GetStr
    End SubPrivate Sub Command1_Click()
        Call GetStr("604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,")
    End Sub
      

  2.   

    利用关键词的唯一性:
    Private Sub Form_Load()
    MsgBox norepeat("604134a,604134b,604134c,604134a,604134d,604134e,604134c,604134d,604134e,")End SubFunction norepeat(ByVal x As String) As String
    On Error Resume Next
    Dim temp, temp2 As New Collection
    temp = Split(x, ",")
    norepeat = ""
    For i = 0 To UBound(temp)
    temp2.Add temp(i), temp(i)
    norepeat = norepeat & "," & temp2(i)
    Next
    Set temp = Nothing
    If Left(norepeat, 1) = "," Then norepeat = Right(norepeat, Len(norepeat) - 1)
    End Function