|
Calling Sequence
|
|
Split( s, sep )
CaseSplit( s )
LengthSplit( s, len )
LengthSplit( s, len, pad = ch )
StringSplit( s, fstr )
|
|
Parameters
|
|
s
|
-
|
string; string to split
|
sep
|
-
|
(optional) string; separator that indicates where to split string s
|
len
|
-
|
posint; the length of substrings into which s is to be split
|
ch
|
-
|
character; character to use for padding the last string to length len
|
fstr
|
-
|
string; fixed string on which to split s
|
|
|
|
|
Description
|
|
•
|
The Split(s, sep) command splits string s into substrings that are separated by the optional designated characters sep. If sep is not included in the calling sequence, string s is split on whitespace characters. A list of substrings of the input string s is returned.
|
•
|
The Split(s) form of the calling sequence is equivalent to
|
•
|
The characters that appear in the optional sep parameter are called separator characters (for the splitting operation). The substrings returned by Split(s, sep) are those obtained by taking all maximal substrings of s that do not contain a separator character.
|
|
Note: Each pair of consecutive separator characters in the input string cause an empty string to appear in the output. These can be filtered out.
|
•
|
The CaseSplit(s) command splits a string at uppercase letters. Each uppercase letter in the string begins a new string in the split list.
|
•
|
The LengthSplit command splits the string s into substrings of length len. An expression sequence of the substrings is returned. If len divides evenly into (and is not the empty string), then each substring has length exactly len; otherwise, the last substring has length equal to .
|
|
If the pad option is provided in a call to LengthSplit, the last substring will be "padded" out to length len using the given character as padding.
|
|
If len is greater than or equal to , then s is returned.
|
|
Note: is equivalent to .
|
•
|
The StringSplit( s, fstr ) command splits a string s at a fixed string fstr. This is equivalent to RegSplit( fstr, s ), but is much more efficient, and should therefore be preferred when fstr is a fixed string without regular expression metacharacters.
|
•
|
All of the StringTools package commands treat strings as (null-terminated) sequences of -bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
|
|
|
Examples
|
|
>
|
|
| (1) |
>
|
|
| (3) |
>
|
|
| (4) |
Remove interleaved empty strings, caused by consecutive white space characters, that are likely to be unwanted for many applications.
>
|
|
| (5) |
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
Note the distinction between Split, which splits a string on a set of characters, and StringSplit, which splits a string on the entire string.
>
|
|
>
|
|
| (12) |
>
|
|
| (13) |
|
|
Compatibility
|
|
•
|
The StringTools[StringSplit] command was introduced in Maple 15.
|
|
|
|