Navigation:  ThinBASIC Modules > Core (thinBasic Core Engine) > String functions >

StrDistance

Previous pageReturn to chapter overviewNext page

 

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.

 

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