This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.
This version is copyright and may only be used for local testing purposes. It may not be distributed.
Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.
Description
Levenshtein string distance algorithm (string similarity test)
Levenshtein distance is a measure of the similarity between two strings-
Syntax
n = StrDistance(Str1, Str2 [, CaseSensitive])
Returns
Number
Parameters
Name |
Type |
Optional |
Meaning |
Str1 |
String |
No |
String 1 |
Str2 |
String |
No |
String 1 |
CaseSensitive |
Number |
Yes |
%TRUE or %FALSE if comparison has to consider letter case. Default value is %FALSE. |
Remarks
The distance is the number of deletions, insertions, or substitutions required to transform Str1 into Str2.
For example, If Str1 is "test" and t is "test", then StrDistance(s,t) = 0, because no transformations are needed. The strings are already identical.
If Str1 is "test" and Str2 is "tent", then StrDistance(s,t) = 1, because one substitution (change "s" to "n") is sufficient to transform Str1 into Str2.
The greater the Levenshtein distance, the more different the strings are.
Levenshtein distance name comes from the Russian scientist Vladimir Levenshtein, who devised the algorithm in 1965.
The metric is also sometimes called edit distance.
Restrictions
See also
https://en.wikipedia.org/wiki/Levenshtein_distance
Examples
Uses "Console"
'---Test the StrDistance function
Sub TestStrDistance()
Dim str1 As String = "kitten"
Dim str2 As String = "sitting"
Integer distance = StrDistance(str1, str2)
Printl $("Levenshtein distance between [{str1}] and [{str2}] is: "), distance
End Sub
'---Run the test
TestStrDistance()
WaitKey