Split
StringArray = Split ( String [ , Separators , Escape , IgnoreVoid , KeepEscape ] )
Split a string into sub-strings delimited by separators and escape characters.
Arguments
-
String : The string to split.
-
Separators : The list of separator characters.
-
Escape : Escaping description string.
-
IgnoreVoid : A boolean that tells not to return void elements.
-
KeepEscape : A boolean that tells to keep the encountered escape characters in the returned strings.
Return value
This function returns a string array of the split elements.
Description
This function splits a string into elements delimited by separators and escape characters.
By default, the comma character is the separator, and there are no escape characters.
If an escape description is specified, it allows a split sub-string to include the split characters, provided that the sub-string is enclosed between the escape characters:
-
If the escape description is made of one character, then the initial and final escape character are that character.
And if two successive escape characters are encountered, only one character is kept, and it is not considered as an escape character anymore.
-
If the escape description is made of two characters, then the first one is the initial escape character, and the second one the final escape character.
The final escape character cannot be escaped.
-
If the escape description is made of three characters, then the first one is the initial escape character, and the second one the final escape character.
The final escape character can be escaped by using the third character.
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 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