StringTools
Split
split a string at designated characters
CaseSplit
split a string at uppercase letters
LengthSplit
split a string into equal length pieces
StringSplit
split a string at a fixed string
Calling Sequence
Parameters
Description
Examples
Compatibility
Split( s, sep )
CaseSplit( s )
LengthSplit( s, len )
LengthSplit( s, len, pad = ch )
StringSplit( s, fstr )
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
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
s→Splits,"\t\r\n\f";
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 length⁡s (and s is not the empty string), then each substring has length exactly len; otherwise, the last substring has length equal to irem⁡length⁡s,len.
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 length⁡s, then s is returned.
Note: LengthSplit⁡s,1 is equivalent to Explode⁡s.
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 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
with⁡StringTools:
Split⁡This is a test.
This,is,a,test.
Split⁡This:is:a:test.
This:is:a:test.
Split⁡This:is:a:test.,:
L≔Split⁡This string has some extra \t\twhitespace \n in it.
L≔This,string,has,some,,,,extra,,,whitespace,,,,,in,it.
Remove interleaved empty strings, caused by consecutive white space characters, that are likely to be unwanted for many applications.
remove⁡type,L,
This,string,has,some,extra,whitespace,in,it.
CaseSplit⁡LinearAlgebra
Linear,Algebra
LengthSplit⁡abcdefgh,2
ab,cd,ef,gh
LengthSplit⁡abcdefgh,3
abc,def,gh
LengthSplit⁡abcdefgh,4
abcd,efgh
LengthSplit⁡abcdefgh,3,:-pad=0
abc,def,gh0
StringSplit⁡axbxc,x
a,b,c
Note the distinction between Split, which splits a string on a set of characters, and StringSplit, which splits a string on the entire string.
drseuss≔Think left and think right and think low and think high. Oh, the things you can think if only you try!:
StringSplit⁡drseuss,think
Think left and , right and , low and , high. Oh, the things you can , if only you try!
Split⁡drseuss,think
T,,,, lef, a,d ,,,,, r,g,, a,d ,,,,, low a,d ,,,,, ,,g,. O,, ,,e ,,,,gs you ca, ,,,,, ,f o,ly you ,ry!
The StringTools[StringSplit] command was introduced in Maple 15.
For more information on Maple 15 changes, see Updates in Maple 15.
See Also
irem
length
ListTools[LengthSplit]
string
StringTools[CaseJoin]
StringTools[Explode]
StringTools[Join]
StringTools[RegSplit]
Download Help Document