Hier mal etwas schneller, aber bestimmt noch zu optimierenAND51 hat geschrieben: Hätte hier mal beispielsweise eine Funktion von Perl nach PB portiert: split()Teilt einen String anhand eines Trennzeichens auf und speichert die Teilstrings in Arrays. Das Trennzeichen darf nur ein Zeichen umfassen (bedingt durch StringField).Code: Alles auswählen
Procedure splitStringToArray(Array.s(1), String.s, Separator.s=" ") string+Separator Protected n, num=CountString(String, Separator) ReDim Array.s(num-1) For n=1 To num Array(n-1)=StringField(String, n, Separator) Next ProcedureReturn num EndProcedure Dim woerter.s(51) anzahl=splitStringToArray(woerter(), "I love PureBasic") For n=0 To anzahl-1 Debug woerter(n) Next
Code: Alles auswählen
Procedure splitStringToArray(Array.s(1), String.s, Separator.s = " ")
  Protected *s.Character = @String, Count.l, nString.s, n.l, nSeparator.l = Asc(Separator)
  If String <> ""
    While *s\c <> 0
      If *s\c = nSeparator
        Count + 1
      EndIf
      *s + SizeOf(Character)
    Wend
    *s = @String
    ReDim Array.s(Count)
    For n = 0 To Count
      While *s\c <> nSeparator And *s\c <> 0
        nString + Chr(*s\c)
        *s + SizeOf(Character)
      Wend
      Array.s(n) = nString
      nString = ""
      *s + SizeOf(Character)
    Next
    ProcedureReturn Count + 1
  EndIf
EndProcedure
Dim woerter.s(51)
anzahl=splitStringToArray(woerter(), "I love PureBasic")
For n=0 To anzahl-1
  Debug woerter(n)
Next