现在想要实现 取两个字符串中不同的部分组成新的字符串。
例子:字符串1: 310 字符串2:210 取不同后新的字符串3:32
不要给例子的做法。想要试用所有字符串的 

解决方案 »

  1.   

    Dim i As Integer
    Dim j As Integer
    Text3.Text = CM1
    For i = 1 To Len(CM1)
    For j = 1 To Len(CM2)
    If Mid(CM1, i, 1) = Mid(CM2, j, 1) Then
    Mid(CM1, i, 1) = ""
    Mid(CM2, j, 1) = ""
    End If
    Next j
    Next i
    CM3 = CM1 & CM2
    Text3.Text = CM3
    我这样写的不对  
      

  2.   

    dim s1 as string
    dim s2 as string
    dim s3 as string
    dim p1 as long,L1 as long
    dim s as string
    randomize
    L=len(s1)
    p1=rnd*l
    l1=(l-p1)*rnd
    s=mid(s1,p1,l1)L=len(s2)
    p1=rnd*L
    l1=(l-p1)*rnd
    s=s & mid(s2,p1,l1)
      

  3.   

    Option ExplicitPublic Function Link_Diff(ByVal String1 As String, ByVal String2 As String) As String
    Dim tmp1 As String, tmp2 As String, p As String
    Dim i As Long, j As Long    If Len(String1) <= Len(String2) Then
            tmp1 = String1
            tmp2 = String2
        Else
            tmp1 = String2
            tmp2 = String1
        End If
        
        i = 0
        
        Do While (i < Len(tmp1))
            j = Len(tmp1) - i
            
            Do While j
                p = Mid(tmp1, i + 1, j)
                If InStr(tmp2, p) Then
                    tmp1 = Replace(tmp1, p, "")
                    tmp2 = Replace(tmp2, p, "")
                End If
                
                j = j - 1
            Loop
            i = i + 1
        Loop
        
        If Len(String1) <= Len(String2) Then
            Link_Diff = tmp1 & tmp2
        Else
            Link_Diff = tmp2 & tmp1
        End If
        
    End FunctionPrivate Sub Command1_Click()
        Text3 = Link_Diff(Text1, Text2)
    End Sub
      

  4.   

    我想到了一个用replace的方法  虽然有点多此一举CM1 = Text1.Text
    CM2 = Text2.Text
    cm3 = CM1 & CM2For i = 1 To Len(cm3)
    For j = i + 1 To Len(cm3)
    If Mid(cm3, i, 1) = Mid(cm3, j, 1) Then
    Mid(cm3, i, 1) = "0"
     Mid(cm3, j, 1) = "0"
     End If
    Next j
    Next i
    cm4 = Replace(cm3, "0", "")Text3.Text = cm4