SPLIT

SPLIT s, delim, byref words [, pairs] [USE expr]

Splits the string s at the position of the given delimiters delim and returns an array words with the splitted substrings. The optional parameter pairs can be used to group words. The optional Use expr is applied to every splitted substring. If delim contains more than one character, each character representing a delimiter.

See SINPUT for an alternative command to split a string.

Example 1: Split a string using two delimiters

s = "/etc/temp/filename.ext"
SPLIT s, "/.", v                    ' Splits the string using the delimiters "/" and "."
FOR i = 0 TO UBOUND(v)
  PRINT i; " ["; v(i); "]"
NEXT

' Output:
' 0 []
' 1 [etc]
' 2 [temp]
' 3 [filename]
' 4 [ext]

Example 2 : Using the argument “pairs”

s = "/etc/temp/filename.ext"
SPLIT s, "/", v, "temp"
FOR i = 0 TO UBOUND(v)
  PRINT i;" [";v(i);"]"
NEXT

' Display
0 []
1 [etc/temp]
2 [filename.ext]

Example 3: Using “USE expr”

s = "/etc/temp/filename1.ext  "        ' additional spaces at the end of the string
SPLIT s, "/", v, "temp" USE TRIM(x)    ' trim(x) will remove spaces at the beginning
                                       ' and the end of the splitted strings;
                                       ' try the example without "USE TRIM(x)"
FOR i = 0 TO UBOUND(v)
  PRINT i;" [";v(i);"]"
NEXT

' displays
' 0 []
' 1 [etc/temp]
' 2 [filename1.ext]
String
If there is insufficient information on this page and you wish learn more about SPLIT, please send an email to smallbasic@gmail.com. You can help to improve information about SPLIT by submitting a pull request, click View Source for details. Note, an offline language reference text file is also available - see the Download section.