xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

StrDiff()

Calculates the similarity of two strings.

Syntax

StrDiff( <cString1> , ;
         <cString2> , ;
        [<nReplace>], ;
        [<nDelete>] , ;
        [<nInsert>]   ) --> nSimilarity

Arguments

<cString1> and <cString2>
Thes are two character strings being compared for their similarity.
<nReplace>
The weighing factor for Replace operations defaults to 3. It can be changed to a numeric value between 0 and 255.
<nDelete>
The weighing factor for Delete operations defaults to 6. It can be changed to a numeric value between 0 and 255. Delete operations are considered the most expensive ones.
<nInsert>
The weighing factor for Insert operations defaults to 1. It can be changed to a numeric value between 0 and 255.

Return

The function returns a numeric value indicating the similarity of two character strings.

Description

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.

Info

See also:SetAtLike(), SoundEx()
Category: CT:String manipulation , Character functions
Source:ct\strdiff.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe