StringTools
CommonPrefix
return the length of the longest common prefix of two strings
CommonSuffix
return the length of the longest common suffix of two strings
Calling Sequence
Parameters
Description
Examples
CommonPrefix( s1, s2 )
CommonSuffix( s1, s2 )
s1
-
Maple string
s2
The CommonPrefix(s1, s2) command returns the length of the longest common prefix of its input strings, s1 and s2.
The actual common prefix can be obtained by indexing into either of the strings, s1 or s2, with the range 1 .. CommonPrefix( s1, s2 ).
Note: String t is a prefix of string s if t=s1..n, for some integer 1≤n≤length⁡s, or t is the empty string. For example, the prefixes of the string "abc" are "", "a", "ab", and "abc".
The CommonSuffix(s1, s2) function returns the length of the longest common suffix of its input strings, s1 and s2.
This function can be defined, in terms of CommonPrefix and Reverse as
CommonSuffix⁡s1,s2=CommonPrefix⁡Reverse⁡s1,Reverse⁡s2
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:
CommonPrefix⁡abc,ab
2
CommonPrefix⁡abc,xab
0
CommonPrefix⁡,ab
s≔abc:
t≔ab:
s[ 1 .. CommonPrefix( s, t ) ];
ab
t[ 1 .. CommonPrefix( s, t ) ];
CommonSuffix⁡abc,xbc
CommonSuffix⁡abc,xbcd
See Also
string
StringTools[IsPrefix]
StringTools[IsSuffix]
StringTools[Reverse]
Download Help Document