StringTools - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : List Conversions : StringTools/Split

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 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

$s\to \mathrm{Split}\left(s,"\mathrm{\t\r\n\f}"\right);$

 • 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 $\mathrm{length}\left(s\right)$, then each substring has length exactly len; otherwise, the last substring has length equal to $\mathrm{irem}\left(\mathrm{length}\left(s\right),\mathrm{len}\right)$.
 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 $\mathrm{length}\left(s\right)$, then s is returned.
 Note: $\mathrm{LengthSplit}\left(s,1\right)$ is equivalent to $\mathrm{Explode}\left(s\right)$.
 • 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.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{Split}\left("This is a test."\right)$
 $\left[{"This"}{,}{"is"}{,}{"a"}{,}{"test."}\right]$ (1)
 > $\mathrm{Split}\left("This:is:a:test."\right)$
 $\left[{"This:is:a:test."}\right]$ (2)
 > $\mathrm{Split}\left("This:is:a:test.",":"\right)$
 $\left[{"This"}{,}{"is"}{,}{"a"}{,}{"test."}\right]$ (3)
 > $L≔\mathrm{Split}\left("This string has some extra whitespace in it."\right)$
 ${L}{≔}\left[{"This"}{,}{"string"}{,}{"has"}{,}{"some"}{,}{""}{,}{""}{,}{""}{,}{"extra"}{,}{""}{,}{""}{,}{"whitespace"}{,}{""}{,}{""}{,}{""}{,}{""}{,}{"in"}{,}{"it."}\right]$ (4)
 > $\mathrm{remove}\left(\mathrm{type},L,""\right)$
 $\left[{"This"}{,}{"string"}{,}{"has"}{,}{"some"}{,}{"extra"}{,}{"whitespace"}{,}{"in"}{,}{"it."}\right]$ (5)
 > $\mathrm{CaseSplit}\left("LinearAlgebra"\right)$
 ${"Linear"}{,}{"Algebra"}$ (6)
 > $\mathrm{LengthSplit}\left("abcdefgh",2\right)$
 ${"ab"}{,}{"cd"}{,}{"ef"}{,}{"gh"}$ (7)
 > $\mathrm{LengthSplit}\left("abcdefgh",3\right)$
 ${"abc"}{,}{"def"}{,}{"gh"}$ (8)
 > $\mathrm{LengthSplit}\left("abcdefgh",4\right)$
 ${"abcd"}{,}{"efgh"}$ (9)
 > $\mathrm{LengthSplit}\left("abcdefgh",3,':-\mathrm{pad}'="0"\right)$
 ${"abc"}{,}{"def"}{,}{"gh0"}$ (10)
 > $\mathrm{StringSplit}\left("axbxc","x"\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}\right]$ (11)

Note the distinction between Split, which splits a string on a set of characters, and StringSplit, which splits a string on the entire string.

 > $\mathrm{drseuss}≔"Think left and think right and think low and think high. Oh, the things you can think if only you try!":$
 > $\mathrm{StringSplit}\left(\mathrm{drseuss},"think"\right)$
 $\left[{"Think left and"}{,}{"right and"}{,}{"low and"}{,}{"high. Oh, the things you can"}{,}{"if only you try!"}\right]$ (12)
 > $\mathrm{Split}\left(\mathrm{drseuss},"think"\right)$
 $\left[{"T"}{,}{""}{,}{""}{,}{""}{,}{"lef"}{,}{"a"}{,}{"d"}{,}{""}{,}{""}{,}{""}{,}{""}{,}{"r"}{,}{"g"}{,}{""}{,}{"a"}{,}{"d"}{,}{""}{,}{""}{,}{""}{,}{""}{,}{"low a"}{,}{"d"}{,}{""}{,}{""}{,}{""}{,}{""}{,}{""}{,}{""}{,}{"g"}{,}{". O"}{,}{","}{,}{""}{,}{"e"}{,}{""}{,}{""}{,}{""}{,}{"gs you ca"}{,}{""}{,}{""}{,}{""}{,}{""}{,}{""}{,}{""}{,}{"f o"}{,}{"ly you"}{,}{"ry!"}\right]$ (13)

Compatibility

 • The StringTools[StringSplit] command was introduced in Maple 15.
 • For more information on Maple 15 changes, see Updates in Maple 15.

 See Also

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam