Split

StringArray = Split ( String [ , Separators , Escape , IgnoreVoid , KeepEscape ] )

Split a string into substrings delimited by separators and escape characters.

  • String is the string to split.

  • Separators is a list of separator characters.

  • Escape is an escape character. Any separator characters enclosed between two escape characters are ignored in the splitting process. If Escape contains two characters, then the first is the starting escape character, and the second the ending one.

  • IgnoreVoid is a boolean that tells Split() not to return void elements.

  • KeepEscape is a boolean that tells to keep the encountered escape characters in the returned strings.

This function returns a string array filled with each detected substring. Separators and escape characters are not returned.

By default, the comma character is the separator, and there are no escape characters.

If two successive right escape characters are encountered, only one character is kept, and it is not considered as an escape character anymore.

This is the way Split() quotes the right escape character, allowing it to be part of a splitted element.

Separator and escape characters are just single one-byte ASCII characters. You cannot use this function to split a string with a non-ASCII character or a another string.

For example: Split(MyString, "\r\n") will split MyString by using "\r" or "\n" as separator, but not the full string "\r\n".

Examples

Dim Elt As String[]
Dim Sb As String

Elt = Split(" Gambas Almost Means BASIC  !\n'Do you agree ?'", " \n", "'")

FOR EACH Sb IN Elt
  PRINT "("; Sb; ") ";
NEXT
PRINT
() (Gambas) (Almost) (Means) (BASIC) () (!) (Do you agree ?)

Dim Elt As String[]
Dim Sb As String

Elt = Split(" Gambas Almost Means BASIC  !\n'Do you agree ?'", " \n", "'", TRUE)

FOR EACH Sb IN Elt
  PRINT "("; Sb; ") ";
NEXT
PRINT
(Gambas) (Almost) (Means) (BASIC) (!) (Do you agree ?)

Dim Elt As String[]
Dim Sb As String

Elt = Split("(Gambas) (Almost) (Means) (BASIC) (!) (Do you agree ?)", " ", "()")

FOR EACH Sb IN Elt
  PRINT Sb; ".";
NEXT
PRINT
Gambas.Almost.Means.BASIC.!.Do you agree ?.

See also