fb:porticula NoPaste
stringSplit & stringReplace
Uploader: | MOD |
Datum/Zeit: | 27.09.2013 23:13:45 |
Sub stringSplit(text As String, separator As String, array() As String)
Dim As Integer i, arrayIndex, lb = LBound(array)
If @array(lb) = 0 Then
arrayIndex = 0
ReDim array(1)
For i = 0 To Len(text) - 1
If separator[1] = 0 Then
If text[i] = separator[0] Then
arrayIndex += 1
ReDim Preserve array(arrayIndex)
Else
array(arrayIndex) &= Chr(text[i])
EndIf
Else
If Mid(text, i + 1, Len(separator)) = separator Then
arrayIndex += 1
i += Len(separator) - 1
ReDim Preserve array(arrayIndex)
Else
array(arrayIndex) &= Chr(text[i])
EndIf
EndIf
Next
Else
Dim As Integer ub = UBound(array)
arrayIndex = lb
For i = 0 To Len(text) - 1
If separator[1] = 0 Then
If text[i] = separator[0] Then
If arrayIndex < ub Then
arrayIndex += 1
Else
array(arrayIndex) &= Chr(separator[0])
EndIf
Else
array(arrayIndex) &= Chr(text[i])
EndIf
Else
If Mid(text, i + 1, Len(separator)) = separator Then
If arrayIndex < ub Then
arrayIndex += 1
i += Len(separator) - 1
Else
array(arrayIndex) &= Chr(text[i])
EndIf
Else
array(arrayIndex) &= Chr(text[i])
EndIf
EndIf
Next
EndIf
End Sub
Function stringReplace( text As String, old_ As String, new_ As String ) As String
Dim As String ret
Dim As String array( )
stringSplit( text, old_, array( ) )
Dim As Integer i
For i = LBound( array ) To UBound( array ) - 1
ret &= array( i ) & new_
Next
ret &= array( i )
Return ret
End Function
Print stringReplace( "abcabcabc", "ab", "d" )
Dim As String datum = "#Tag# #Monat# #Jahr#"
datum = stringReplace( datum, "#Tag#", "01" )
datum = stringReplace( datum, "#Monat#", "10" )
Print stringReplace( datum, "#Jahr#", "2013" )
Print stringReplace( "cabcc", "ab", "d" )
Print stringReplace( "cab", "ab", "d" )
Print stringReplace( "abc", "ab", "d" )
Sleep