Chop or split a string into substrings.
String_Type[] strchop (String_Type str, Integer_Type delim,
Integer_Type quote)
The strchop function may be used to split-up a string
str that consists of substrings delimited by the character
specified by delim. If the integer quote is non-zero,
it will be taken as a quote character for the delimiter. The
function returns the substrings as an array.
The following function illustrates how to sort a comma separated
list of strings:
define sort_string_list (a)
{
variable i, b, c;
b = strchop (a, ',', 0);
i = array_sort (b, &strcmp);
b = b[i]; % rearrange
% Convert array back into comma separated form
return strjoin (b, ",");
}
The semantics of this strchop and strchopr have been
changed since version 1.2.x of the interpreter. Old versions of
these functions returned the values on the stack, which meant that
one could not chop up arbitrarily long strings that consist of
many substrings.
The function strchopr should be used if it is desired to have
the string chopped-up in the reverse order.
|