StringTools
Take
extract a prefix from a string
Drop
remove a prefix from a string
Calling Sequence
Parameters
Description
Examples
Take( s, len )
Take( s, delim )
Drop( s, len )
Drop( s, delim )
s
-
Maple string
len
non-negative integer; length of prefix to extract or remove
delim
string; set of characters (delimiters)
The Take(s, len) command returns the prefix of length len from string s.
If s has at least len characters, then the substring of s consisting of the first len characters of s is returned. That is, the string s1..len is returned. If s has length less than len, then s is returned.
The Drop(s, len) command removes the prefix of length len from string s.
If the length of s is greater than or equal to len, then the string s1+len..−1 is returned. If the length of s is less than len, then an empty string is returned.
If the second argument is a string delim, it is interpreted as a set of delimiting characters. In this case, the Take( s, delim ) command returns the prefix of s consisting of characters not in the string delim. The Drop( s, delim ) command returns the suffix of s consisting of characters not in the string delim.
Take and Drop satisfy the equation
s=cat⁡Take⁡s,n,Drop⁡s,n
for all non-negative integers n.
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:
seq⁡Take⁡abcde,i,i=0..6
,a,ab,abc,abcd,abcde,abcde
seq⁡Take⁡,i,i=0..6
,,,,,,
seq⁡Drop⁡abcde,i,i=0..6
abcde,bcde,cde,de,e,,
seq⁡Drop⁡,i,i=0..6
seq⁡cat⁡Take⁡abcde,i,Drop⁡abcde,i,i=0..6
abcde,abcde,abcde,abcde,abcde,abcde,abcde
Take⁡abcde,ec
ab
Drop⁡abcde,ec
See Also
cat
seq
string
StringTools[IsPrefix]
StringTools[Join]
StringTools[Split]
StringTools[SubString]
Download Help Document