strdistance()
strdistance()
Section titled “strdistance()”strdistance(<source>, <target>[, <ignore case>[, <transpositions>]])
strdistance() returns how many characters must be added, removed or changed to turn <source> into <target>. Each of those costs one, so swapping two characters costs two. Case matters, and markup is ignored.
When <ignore case> is 1, case does not matter. When <transpositions> is 1, swapping two neighbouring characters costs one.
A character is what the screen shows as one: an emoji, or a letter with an accent written as a separate mark, counts once. A letter with its accent built in, chr(233), and the same letter written as e[chr(769)] look alike but differ.
Use it to suggest the help topic or keyword a player probably meant, and let them choose it. Never use a near match to pick the target of a command that changes or destroys something.
- strdistance limits: identical and empty inputs, and the work bounds
- strdistance examples: plain words, markup, wide characters and emoji
Empty inputs and limits
Section titled “Empty inputs and limits”Two identical inputs return 0. When one is empty, the result is the number of characters in the other.
Each input can be at most 65,536 characters long and hold at most 4,096 characters as the screen counts them, and the two counts multiplied together at most 4,000,000. Past these, strdistance() returns #-1 STRING DISTANCE WORK LIMIT EXCEEDED.
Examples
Section titled “Examples”> think strdistance(kitten,sitting)3> think strdistance(ab,ba)2> think strdistance(this,This,1)0> think strdistance(the,teh,,1)1> think strdistance(ansi(r,[chr(30028)][chr(128512)]),[chr(30028)][chr(128570)])1> think strdistance(,e[chr(769)][chr(128512)])2chr(30028) is a wide Chinese character, chr(128512) and chr(128570) two different emoji (a grinning face and a grinning cat face), and e[chr(769)] an e followed by an accent mark.
::: seealso