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

Parameters

Description

Examples

Compatibility

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

sSplits,"\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 lengths, then each substring has length exactly len; otherwise, the last substring has length equal to iremlengths,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 lengths, then s is returned.

  

Note: LengthSplits,1 is equivalent to Explodes.

• 

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

withStringTools:

SplitThis is a test.

This,is,a,test.

(1)

SplitThis:is:a:test.

This:is:a:test.

(2)

SplitThis:is:a:test.,:

This,is,a,test.

(3)

LSplitThis string has some extra whitespace in it.

L:=This,string,has,some,,,,extra,,,whitespace,,,,,in,it.

(4)

removetype,L,

This,string,has,some,extra,whitespace,in,it.

(5)

CaseSplitLinearAlgebra

Linear,Algebra

(6)

LengthSplitabcdefgh,2

ab,cd,ef,gh

(7)

LengthSplitabcdefgh,3

abc,def,gh

(8)

LengthSplitabcdefgh,4

abcd,efgh

(9)

LengthSplitabcdefgh,3,':-pad'=0

abc,def,gh0

(10)

StringSplitaxbxc,x

a,b,c

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

drseussThink left and think right and think low and think high. Oh, the things you can think if only you try!:

StringSplitdrseuss,think

Think left and , right and , low and , high. Oh, the things you can , if only you try!

(12)

Splitdrseuss,think

T,,,, lef, a,d ,,,,, r,g,, a,d ,,,,, low a,d ,,,,, ,,g,. O,, ,,e ,,,,gs you ca, ,,,,, ,f o,ly you ,ry!

(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

irem

length

ListTools[LengthSplit]

string

StringTools

StringTools[CaseJoin]

StringTools[Explode]

StringTools[Join]

StringTools[RegSplit]

 


Download Help Document

Was this information helpful?



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