IsPrefix - Maple Help

StringTools

 IsPrefix
 test for an initial substring
 IsSuffix
 test for a terminal substring

 Calling Sequence IsPrefix( s, t ) IsSuffix( s, t )

Parameters

 s, t - Maple strings

Description

 • The IsPrefix( s, t ) command determines whether s is a prefix (initial substring) of t.
 The string s is a prefix of the string t if $\mathrm{s1}={t}_{1..n}$, for some integer $1\le n$, or s is the empty string.
 If s is a prefix of t, IsPrefix returns true. Otherwise, false is returned.
 Note: The IsPrefix( s, t ) command is equivalent to the expression

 member( s, [ seq( t[ 1 .. i ], i = 0 .. length( t ) ) ] ).

 • The IsSuffix( s, t ) command determines whether s is a suffix (terminal substring) of t.
 If s is a suffix of t, IsSuffix returns true. Otherwise, false is returned.
 Note: The IsSuffix( s, t ) command is equivalent to the expression

 member( s, [ seq( t[ i .. -1 ], i = 1 .. 1 + length( t ) ) ] )

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

 • The StringTools[IsPrefix] and StringTools[IsSuffix] commands are thread-safe as of Maple 15.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{IsPrefix}\left("","abc"\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{IsPrefix}\left("a","abc"\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{IsPrefix}\left("ab","abc"\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{IsPrefix}\left("abc","abc"\right)$
 ${\mathrm{true}}$ (4)
 > $\mathrm{IsPrefix}\left("abcd","abc"\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{IsPrefix}\left("ac","abc"\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{IsSuffix}\left("","abc"\right)$
 ${\mathrm{true}}$ (7)
 > $\mathrm{IsSuffix}\left("c","abc"\right)$
 ${\mathrm{true}}$ (8)
 > $\mathrm{IsSuffix}\left("bc","abc"\right)$
 ${\mathrm{true}}$ (9)
 > $\mathrm{IsSuffix}\left("abc","abc"\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{IsSuffix}\left("xabc","abc"\right)$
 ${\mathrm{false}}$ (11)
 > $\mathrm{IsPrefix}\left("foo","foobar"\right)$
 ${\mathrm{true}}$ (12)
 > $S≔\left[\mathrm{seq}\right]\left("foobar"\left[1..i\right],i=0..\mathrm{length}\left("foobar"\right)\right)$
 ${S}{≔}\left[{""}{,}{"f"}{,}{"fo"}{,}{"foo"}{,}{"foob"}{,}{"fooba"}{,}{"foobar"}\right]$ (13)
 > $\mathrm{member}\left("foo",S\right)$
 ${\mathrm{true}}$ (14)
 > $s≔\mathrm{Random}\left(100\right):$
 > $\mathrm{length}\left(s\right)$
 ${100}$ (15)
 > $\left\{\mathrm{seq}\left(\mathrm{IsSuffix}\left(\mathrm{Drop}\left(s,i\right),s\right),i=1..\mathrm{length}\left(s\right)\right)\right\}$
 $\left\{{\mathrm{true}}\right\}$ (16)
 > $\left\{\mathrm{seq}\left(\mathrm{IsPrefix}\left(\mathrm{Take}\left(s,i\right),s\right),i=1..\mathrm{length}\left(s\right)\right)\right\}$
 $\left\{{\mathrm{true}}\right\}$ (17)