比如有 where are you 3个单词
如果得到这3个单词的所有组合?
where are you
where you are
are you where
are where you
you are where
you where are

解决方案 »

  1.   

    str="where are you"
    a=split(str," ")
    function dose(s() as string) 
    if s.count=1 then
    print s(lbound(s))
    else
    for i=lbound(s) to ubound(s)
    print s(i);
    redim s2(lbound(s) to ubound(s) - 1)
    for j = lbound(s) to ubound(s) - 1
    if j<i then
    s2(j) = s(j)
    elseif j>i then
    s2(j) = s(j+1)
    end if
    does s2
    next
    next
    end if
    end function
      

  2.   


    '在Form1窗体上添加一个Command按钮。
    Private Sub Command1_Click()
        Dim s As String
        Dim v
        Dim v1
        Dim i As Integer
        Dim j As Integer
        Dim sLine As String
        
        s = "where are you"
        v = Split(s, " ")
        v1 = v
        
        For i = LBound(v) To UBound(v)
            sLine = v(i)
            For j = LBound(v1) To UBound(v1)
                If v(i) <> v(j) Then
                    sLine = sLine & " " & v(j)
                End If
            Next
            Debug.Print sLine
            
            sLine = v(i)
            For j = UBound(v1) To LBound(v1) Step -1
                If v(i) <> v(j) Then
                    sLine = sLine & " " & v(j)
                End If
            Next
            Debug.Print sLine
        Next
        
    End Sub
      

  3.   

    Dim f As StringPrivate Sub Form_Click()
    Dim str As String, a() As String
    str = "where are you a"
    a = Split(str, " ")
    f = ""
    printstr a
    End Sub
     
    Sub printstr(s() As String)
        Dim s2() As String, k As String
        If UBound(s) - LBound(s) = 0 Then
            Print f & " " & s(LBound(s))
        Else
            For i = LBound(s) To UBound(s)            ReDim s2(LBound(s) To UBound(s) - 1)
                For j = LBound(s) To UBound(s) - 1
                    If j < i Then
                        s2(j) = s(j)
                    Else
                        s2(j) = s(j + 1)
                    End If
                Next
                k = f
                f = f & " " & s(i)
                printstr s2
                f = k
            Next
        End If
    End Sub
    終於搞出來了哎