Skip to content

String.Split

boxgaming edited this page Aug 5, 2025 · 4 revisions

Takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.

Syntax

String.Split s$, delimiter$, results$() [, regex%]

Parameters

  • The s$ parameter contains the string to split.
  • The searchStr$ indicates the search pattern for the delimiter that will be used to split the string.
  • The results$() parameter is a string array that will contain the results of the split.
  • If true (non-zero) the optional regex& parameter indicates that the delimiter$ parameter should be evaluated as a regular expression. By default, it will be treated as a plain string.

Example

Import String From "lib/lang/string.bas"

ReDim result(0) As String
String.Split "one|two|three", "|", result()
PrintResults result()

String.Split "red  " + Chr$(10) + "green       blue orange", "\s+", result(), -1
PrintResults result()

Sub PrintResults (result() As String)
    Print "-------------["; UBound(result); "]----------------"
    For i=1 To UBound(result)
        Print result(i)
    Next i
End Sub

Output

-------------[3]----------------
one
two
three
-------------[4]----------------
red
green
blue
orange

See Also

String.Match
Javascript - String.split()

Clone this wiki locally