dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB6
Expertise: Intermediate
Jun 23, 2003

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


PermuteString - Generating all possible combinations out of a string

' Generates all combination possibilities out of a string
Public Function PermuteString(ByVal Ztring As String, Optional Base As String = _
    "") As String
    Dim TmpStrArray() As String, I As Long
    
    ' If there's only 1 element then
    If InStr(1, Ztring, " ", vbTextCompare) = 0 Then
        PermuteString = Base & " " & Ztring & vbCrLf
        Exit Function
    End If
     
    ' If more than 1 element: split elements in one array of elements
    TmpStrArray = Split(Ztring, " ", , vbTextCompare)
     
    If Base = "" Then
        ' Loop trough each element and do callbacks to permute again
        For I = LBound(TmpStrArray) To UBound(TmpStrArray)
            PermuteString = PermuteString & PermuteString(ReturnAllBut _
                (TmpStrArray, I), TmpStrArray(I))
        Next
    Else
        ' Loop trough each element and do callbacks to permute again
        For I = LBound(TmpStrArray) To UBound(TmpStrArray)
            PermuteString = PermuteString & " " & PermuteString(ReturnAllBut _
                (TmpStrArray, I), Base & " " & TmpStrArray(I))
        Next
    End If 
End Function

' Return all items in a array but 1
Public Function ReturnAllBut(ByRef Arrai() As String, But As Long) As String
    Dim I As Long
    For I = LBound(Arrai) To UBound(Arrai)
        If I <> But Then
            ReturnAllBut = ReturnAllBut & Arrai(I) & " "
        End If
    Next
    ReturnAllBut = RTrim(ReturnAllBut)
End Function


' Pay a visit to the author's web site at http://www15.brinkster.com/bubux/
BubuX World
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date