有字符串1   "9 1 10 6 13"
另一字符串2   "9 10 11 12 13"查找字符串1中是否 有任意3个数字 在字符串2中 例子中 9 10 13为这3个数 
如果有则 则显示出"有3个数相同" 并且显示出字符串2中另外2个数字 例子中为11 12有好的方法编程得到吗?
谢了

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim tempStr1() As String, tempStr2() As String
        Dim Str1 As String, Str2 As String, temp As String
        Dim i As Integer, j As Integer, N As Integer, F() As Boolean
        
        Str1 = "9 1 10 6 13"
        Str2 = "9 10 11 12 13"
        
        tempStr1 = Split(Str1)
        tempStr2 = Split(Str2)
        ReDim F(UBound(tempStr2))
        
        For i = 0 To UBound(tempStr1)
            For j = 0 To UBound(tempStr2)
                If tempStr1(i) = tempStr2(j) Then
                   F(j) = True
                   N = N + 1
                End If
            Next j
        Next i
        
        If N = 3 Then
           For i = 0 To UBound(tempStr2)
               If Not F(i) Then temp = temp + tempStr2(i) + " "
           Next i
           
           MsgBox "有3个数据相同,不同数为:" & temp
        End If
      

  2.   

    a = "9 1 10 6 13" 
    b = "9 10 11 12 13" arr_a = split(a," ")
    arr_b = split(b," ")set dict = createobject("scripting.dictionary")
    for i=lbound(arr_b) to ubound(arr_b)
    call dict.add(arr_b(i),null)
    nextfor i=lbound(arr_a) to ubound(arr_a)
    if dict.exists(arr_a(i)) then
    call msgbox(arr_a(i))
    end if
    next
    将以上代码复制到记事本中,保存为test.vbs,然后双击运行即可.
      

  3.   

    a = "9 1 10 6 13" 
    b = "9 10 11 12 13" arr_a = split(a," ")
    arr_b = split(b," ")for i=lbound(arr_a) to ubound(arr_a)
    For j=LBound(arr_b) To UBound(arr_b)
    If arr_a(i) = arr_b(j) Then
    Call MsgBox(arr_a(i))
    End If
    Next
    Next
    这样也可以:->
      

  4.   

    Private Sub Form_Load()
    S1 = "9 1 10 6 13"
    S2 = "9 10 11 12 13"
    A = Split(S1, " ")
    B = Split(S2, " ")
    For i = 0 To UBound(A)
    For J = 0 To UBound(A)
    If A(i) = B(J) Then
    k = k + 1
    Debug.Print A(i)
    End If
    Next
    Next
    Debug.Print "有" & k & "个数相同"
    End Sub
      

  5.   

    Option ExplicitPrivate Sub Command1_Click()        Dim Str1 As String, Str2 As String
            Dim S1() As String, S2() As String, S3() As String
            Dim S As String
            Dim i As Integer, j As Integer, m As Integer, n As Integer
            
            Str1 = "9 1 10 6 13"
            Str2 = "9 10 11 12 13"
            
            S1 = Split(Str1, " "): S2 = Split(Str2, " ")
            
            m = 0: n = 0
            
            For i = 0 To UBound(S1)
                For j = 0 To UBound(S2)
                    If Val(S1(i)) = Val(S2(j)) Then
                       m = m + 1: S = S & (S1(i) & " ")
                       Debug.Print "相同的数是:" & S1(i)
                    End If
                Next
            Next
            
            n = UBound(S2) + 1 - m
            
            S3 = Split(S, " ")
            
            For i = 0 To UBound(S2)
                For j = 0 To UBound(S3)
                    If Val(S2(i)) = Val(S3(j)) Then
                       S2(i) = ""
                    End If
                Next
                If Len(S2(i)) <> 0 Then Debug.Print "不相同的数是:" & S2(i)
            Next
            
            Debug.Print "共有" & m & "个相同的数!", "共有" & n & "个不相同的数!"
                    
    End Sub