fb:porticula NoPaste
4TPM
Uploader: | ytwinky |
Datum/Zeit: | 18.10.2007 16:15:18 |
Declare sub F_SplitString(V_Data as string, B_DD() as string, byref B_DC as long, V_CutString as string, V_ClearArray as byte, V_Casesensitivity as Byte, V_AddEmpty as Byte)
Sub PrintArray(Titel As String, Liste As String, dd() As String, Trenner As String, LeerZeilen As Integer=1=1)
var dc=0
If Titel<>"" Then Print Titel
F_SplitString(Liste, dd(), dc, Trenner, 1, 0, 1)
For i As Integer=0 To dc
Print Using"i=#### ";i;
Print " >" &dd(i) &"<"
Next
End Sub
Dim As Integer i, dc
Dim dd() As String
Print "Eingabe: " &command(0) &" " &command
Print String(10, "-")
F_SplitString(Command, dd(), dc, " ", dc, 0, 1)
Print "Count:" &dc
For i=1 To dc
Print i &" >" &dd(i) &"<"
Next
Const CrLf=!"\r\n"
Dim As String Liste="a;;bb;;ccc;;;;dddd;;eeeee;;ffffff", Trenner=";;", s
s="Hallo," &CrLf
s+="StringSplit entstand aus SubStr.Bas" &CrLf
s+="Es l„uft mit FB0.16b, mit FB0.17f und auch mit FB0.181f" &CrLf
s+="Aufruf: i=StringSplit(Liste, Trenner[, LeerZeilen])" &CrLf
s+="Parameter:" &CrLf
s+="Liste ein String mit den Daten und bestimmten Trennzeichen" &CrLf
s+=!"Trenner ein String mit Trennzeichen (also auch mehrere!!)\r\n" _
!"LeerZeilen False: Leerzeile ausfiltern, True: Leerzeilen behalten\r\n" _
!"Ausgabe: Anzahl der Zeilen-1\r\n" _
!"Die Zeilen selbst werden im Shared Array SplitArray gespeichert\r\n" _
!"(Daá dies vorhanden ist, muá vom Programmierer sichergestellt werden..)\r\n" _
!"SplitArray beginnt immer bei 0 und endet bei UBound(SplitArray)\r\n" _
!"Falls erforderlich, müssen die Ergebnisse umkopiert werden..\r\n" _
!"hf..\r\n"
PrintArray("1. String:", Liste, dd(), Trenner, 1=0)
PrintArray("2. String:", s, dd(), CrLf)
Print "3. String:"
dc=0
F_SplitString("Geht auch..", dd(), dc, CrLf, 0, 0, 1)
Print i, dd(dc)
PrintArray("4. String:", "Das natrlich auch..", dd(), "\r\n")
Print "Eniki..";
Sleep
sub F_SplitString(V_Data as string, B_DD() as string, byref B_DC as long, V_CutString as string, V_ClearArray as byte, V_Casesensitivity as Byte, V_AddEmpty as Byte)
if V_ClearArray = 1 then b_dc = 0
redim preserve b_dd(b_dc) as string
Dim X as long
Dim Pos1 as long
Dim Pos2 as long
Dim SLen as long
Dim T as string
Dim S as string
Dim XOK as byte
s = v_cutstring
if V_Casesensitivity = 0 then s = lcase(v_cutstring)
SLen = len(s)
pos1 = 1
pos2 = 1
for x = 1 to len(v_data) - slen
if V_Casesensitivity = 0 then
if lcase(mid(v_data,x,slen)) = s then
t = mid(v_data,pos1,x-pos1+slen)
x+= slen-1
pos1 = x+1
endif
else
if mid(v_data,x,slen) = v_cutstring then
t = mid(v_data,pos1,x-pos1+slen)
x+= slen
pos1 = x
endif
endif
if pos1 <> pos2 or x = len(v_data) - slen then
if pos1 = pos2 then t = mid(v_data,pos1)
xok = 1
if t = "" then if v_addempty = 0 then xok = 0
if xok = 1 then
b_dc+= 1
redim preserve b_dd(b_dc) as string
b_dd(b_dc) = t
endif
pos2 = pos1
endif
next
end sub