String-Permutation

02/04/2008 - 22:45 von Jonas Felber | Report spam
Hallo, ich habe ein String-Array, das durch "|" unterteilt ist, also
"Haus|Garten|Zaun".
Ich schaffe es zwar, Permutationen zu bilden, aber immer nur mit
3er-Kombis ("Haus+Garten+Zaun","Garten+Haus+Zaun", usw.), obwohl ich
auch "Haus", "Garten", "Haus+Garten", "Haus+Zaun", usw. bràuchte. Ich
schaffe es irgendwie nicht. Kann jemand helfen? Danke.
Jonas

Public Function PermutateString(ByVal input_string As String, Optional
ByVal Base As String = "") As String

Dim i&
Dim TmpStrArray() As String

'If there's only 1 element, then
If InStr(1, input_string, "|", vbTextCompare) = 0 Then
PermutateString = Base & "+" & input_string & "|"
Exit Function
End If

'If more than 1 element, split elements in one array of elements
TmpStrArray = Split(input_string, "|", , vbTextCompare)

If Base = "" Then
'Loop trough each element and do callbacks to permutate again
For i = LBound(TmpStrArray) To UBound(TmpStrArray)
PermutateString = PermutateString &
PermutateString(ReturnAllBut(TmpStrArray, i), TmpStrArray(i))
Next
Else
'Loop trough each element and do callbacks to permutate again
For i = LBound(TmpStrArray) To UBound(TmpStrArray)
PermutateString = PermutateString &
PermutateString(ReturnAllBut(TmpStrArray, i), Base & " " & TmpStrArray(i))
Next
End If

End Function

Private Function ReturnAlllExclude(ByRef strArray() As String, ByVal
lExclude As Long) As String

Dim i&
For i = LBound(strArray) To UBound(strArray)
If i <> lExclude Then
ReturnAlllExclude = ReturnAlllExclude & strArray(i) & " "
End If
Next
ReturnAlllExclude = RTrim(ReturnAlllExclude)

End Function
 

Lesen sie die antworten

#1 Jonas Felber
02/04/2008 - 22:55 | Warnen spam
Sorry, die Funktion heisst

Public Function ReturnAllBut(

und nicht

Private Function ReturnAlllExclude

Ähnliche fragen