xHarbour Reference Documentation > Function Reference |
Calculates the similarity of two strings.
StrDiff( <cString1> , ; <cString2> , ; [<nReplace>], ; [<nDelete>] , ; [<nInsert>] ) --> nSimilarity
The function returns a numeric value indicating the similarity of two character strings.
The function calculates the Levenshtein distance which indicates the similarity of two character strings. The algorithm weighs Delete, Insert and Replace operations required to transform <cString1> into <cString2>. The weighing factors of each operation influence the result. It is assumed that two strings are more similar the smaller the result is.
See also: | SetAtLike(), SoundEx() |
Category: | CT:String manipulation , Character functions |
Source: | ct\strdiff.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example shows results of StrDiff() for two // similar and to very different strings. PROCEDURE Main ? StrDiff( "Mister", "Miller" ) // result: 6 ? StrDiff( "Clipper", "xHarbour" ) // result: 19 RETURN
http://www.xHarbour.com