Original Author Paul Laughton, 2011
Page 136
De Re BASIC!
String Operations
Split and Join are complementary operations. Split separates a string into parts and put the parts in an
array. Join builds a string by combining the elements of an array.
See also the various String Functions.
Join <source_array$[]>, <result_svar> {, <separator_sexp>{, <wrapper_sexp}}
Join.all <source_array$[]>, <result_svar> {, <separator_sexp>{,
<wrapper_sexp}}
The elements of the <source_array$[]> are joined together as a single string in the <result_svar>. By
default, the source elements are joined with nothing between them or around them.
You may specify optional modifiers that add characters to the string. Copies of the separator string
<separator_sexp> are written between source elements. Copies of the wrapper string <wrapper_sexp>
are placed before and after the rest of the result string.
The Join command omits any empty source elements. The Join.all command includes all source
elements in the result string, even if they are empty. There is no difference between the two commands
unless you specify a non-empty separator string. Join.all places copies of the separator between all of
the elements, including the empty ones.
An example of an operation that uses both separators and wrappers is a CSV string, for "comma-
separated values".
InnerPlanets$ = "Mercury Venus Earth Mars"
SPLIT IP$[], InnerPlanets$
JOIN IP$[], PlanetsCSV$, "\",\"", "\""
PRINT PlanetsCSV$
This prints the string
"Mercury","Venus","Earth","Mars"
(including all of the quotes). The separator
puts the
","
between planet names, and the wrapper puts the
"
at the beginning and end of the string.
Split <result_array$[]>, <sexp> {, <test_sexp>}
Split.all <result_array$[]>, <sexp> {, <test_sexp>}
Splits the source string <sexp> into multiple strings and place them into <result_array$[]>. The array is
specified without an index. If the array exists, it is overwritten. Otherwise a new array is created. The
result is always a one-dimensional array.
The string is split at each location where <test_sexp> occurs. The <test_sexp> occurrences are removed
from the result strings. The <text_sexp> parameter is optional; if it is not given, the string is split on
whitespace. Omitting the parameter is equivalent to specifying "\\s+".