 StringTools - Maple Programming Help

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Miscellaneous Utilities : StringTools/DifferencePositions

StringTools

 DifferencePositions
 compute the character positions at which two strings differ

 Calling Sequence DifferencePositions( s, t )

Parameters

 s - string t - string

Description

 • The DifferencePositions( s, t ) function computes the positions at which the strings s and t differ.  It returns the (ordered) expression sequence of these positions.  If s and t are equal, then NULL is returned. If s and t differ in length, then the positions up to the shorter of s and t are computed and returned.
 • The length of the returned expression sequence is equal to the Hamming distance between s and t, provided that s and t are the same length. (Note that the HammingDistance command computes the generalized Hamming distance for strings of unequal length.)
 • 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.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{DifferencePositions}\left("abc","abc"\right)$
 > $\mathrm{DifferencePositions}\left("abcde","axcye"\right)$
 ${2}{,}{4}$ (1)
 > $\mathrm{HammingDistance}\left("abcde","axcye"\right)$
 ${2}$ (2)
 > $\mathrm{DifferencePositions}\left("abcde","axcyefg"\right)$
 ${2}{,}{4}$ (3)
 > $\mathrm{HammingDistance}\left("abcde","axcyefg"\right)$
 ${4}$ (4)
 > $\mathrm{DifferencePositions}\left("edit","tide"\right)$
 ${1}{,}{2}{,}{3}{,}{4}$ (5)
 > $\mathrm{IsDerangement}\left("edit","tide"\right)$
 ${\mathrm{true}}$ (6)

Compatibility

 • The StringTools[DifferencePositions] command was introduced in Maple 18.