substring - Maple Help

substring

extract a substring from a string

 Calling Sequence substring(string, range, type)

Parameters

 string - string or symbol range - range m..n, or an integer m type - (optional) one of symbol, name, or string

Description

 • The substring function extracts a substring from a string or symbol. By default, if applied to a string, a string is returned. If applied to a symbol, a symbol is returned.
 • If a range is specified for range, and m and n evaluate to integers then substring extracts a substring from string starting with the mth character and ending with the nth character.
 • Specifying a single integer m for range is equivalent to specifying the range m..m.
 • Negative values for m and/or n stand for positions counted leftwards from the right end of the string.  The range 1..-1 refers to the entire string. The range -20..-1 refers to the last 20 characters of the string.
 • If n is greater than the length of string then substring returns a string from the mth character to the end of string. If m is equal to n + 1 then substring returns the null string.
 • If m is greater than the length of string then substring returns the null string.
 • Zero values for m and/or n are not permitted, except for the case m = 1 and n = 0, which returns the null string as described above.
 • If either m or n fails to evaluate to an integer, then substring remains unevaluated.
 • The optional type argument specifies the type of value returned by substring. If type is one of the symbols symbol or name, then a symbol is always returned, even if the first argument is a string. If type is string, then a string is always returned, even if the first argument is a symbol.

 • The substring command is thread-safe as of Maple 15.

Examples

 > $\mathrm{substring}\left(\mathrm{abcdefgh},3..7\right)$
 ${\mathrm{cdefg}}$ (1)
 > $\mathrm{substring}\left(\mathrm{abcdefgh},5\right)$
 ${e}$ (2)
 > $\mathrm{substring}\left("abcdefgh",-5..-1\right)$
 ${"defgh"}$ (3)
 > $\mathrm{substring}\left(\mathrm{wxyz},2..2\right)$
 ${x}$ (4)
 > $\mathrm{substring}\left("abcdefgh",2..4,\mathrm{symbol}\right)$
 ${\mathrm{bcd}}$ (5)
 > $\mathrm{substring}\left(\mathrm{wxyz},2..3,\mathrm{string}\right)$
 ${"xy"}$ (6)