# LevenshteinDist - fonction de script et fonction de graphique

LevenshteinDist() renvoie la distance Levenshtein entre deux chaînes. Cela est défini comme le nombre minimal d'éditions (insertions, suppression ou substitutions) d'un seul caractère requises pour modifier une chaîne dans l'autre. La fonction s'avère utile pour les comparaisons de chaînes partielles.

LevenshteinDist(text1, text2)

entier

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/LevenshteinDist.htm)

#### Exemple : Expression de graphique

| Exemple | Résultat |
| --- | --- |
| `LevenshteinDist('Kitten','Sitting')` | Renvoie '3'. |

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/LevenshteinDist.htm)

#### Exemple : Script de chargement

Script de chargement

```
T1:
Load *, recno() as ID;
Load 'Silver' as String_1,* inline [
String_2
Sliver
SSiver
SSiveer ];

T1:
Load *, recno()+3 as ID;
Load 'Gold' as String_1,* inline [
String_2
Bold
Bool
Bond ];

T1:
Load *, recno()+6 as ID;
Load 'Ove' as String_1,* inline [
String_2
Ove
Uve
Üve ];

T1:
Load *, recno()+9 as ID;
Load 'ABC' as String_1,* inline [
String_2
DEFG
abc
ビビビ ];

set nullinterpret = '<NULL>';
T1:
Load *, recno()+12 as ID;
Load 'X' as String_1,* inline [
String_2
''
<NULL>
1 ];

R1:
Load 
ID, 
String_1, 
String_2, 
LevenshteinDist(String_1, String_2) as LevenshteinDistance 
resident T1;

Drop table T1;
```

Résultat

| ID | String\_1 | String\_2 | LevenshteinDistance |
| --- | --- | --- | --- |
| 1 | Silver | Sliver | 2 |
| 2 | Silver | SSiver | 2 |
| 3 | Silver | SSiveer | 3 |
| 4 | Gold | Bold | 1 |
| 5 | Gold | Bool | 3 |
| 6 | Gold | Bond | 2 |
| 7 | Ove | Ove | 0 |
| 8 | Ove | Uve | 1 |
| 9 | Ove | Üve | 1 |
| 10 | ABC | DEFG | 4 |
| 11 | ABC | abc | 3 |
| 12 | ABC | ビビビ | 3 |
| 13 | X |  | 1 |
| 14 | X | - | 1 |
| 15 | X | 1 | 1 |