STRING::EXPLODE
1g 2023-09-11 laplante@plcb.ca GOWEB — Split Strings into Substringstitle: “STRING::EXPLODE” version: “1.0.0” date: 2023-09-11 author: “laplante@plcb.ca” section: “1g”
string::explode Split Strings into Substrings
string::explode(string [, delimiter, limit])
explode(string [, delimiter, limit])
The explode
function splits a string into a list of substrings based on a given delimiter.
If no delimiter is specified, the string is split into individual characters.
The behavior depends on the limit parameter:
nil
(an empty list).n
substrings; the last substring will contain the unsplit remainder.An alternate function name, splitN
, is also available.
string (string or number, required)
The value to split. If a number is provided, it is first converted to a string.
delimiter (string, optional)
The delimiter to split on. If omitted, splits on each character.
limit (integer, optional)
Controls the number of substrings returned (see rules above).
res={{
explode("514-345-7890", "-"); "\n";
explode("514-345-7890", "-", 2); "\n";
explode("A||B||C", "||"); "\n";
explode("test t2 t3", ""); "\n";
explode("test t2 t3", "", 2); "\n";
explode("ttest t2 t3t", "t"); "\n";
explode("ttest test2 t3t", "test"); "\n";
explode(789, "");
}};
Returns:
res = ["514","345","7890"]
["514","345-7890"]
["A","B","C"]
["t","e","s","t"," ","t","2"," ","t","3"]
["t","est t2 t3"]
["","","es"," ","2 ","3",""]
["t"," ","2 t3t"]
["7","8","9"]