How to measure the similarity between two strings with Dart

Levenshtein distance

Adil Essannouni

--

In dart, Strings are mainly used to represent text. We can compare two sequences using The operator ==. The assertion (string1==string2) returns true if string2 is a String with the same sequence of code units as string1 and false otherwise.
Also, we can use the method compareTo :string1.compareTo(string2);
This method allows comparing string1 to string2. It returns a negative value if string1 is ordered before string2, a positive value if string1 is ordered after string2, or zero if string1 and string2 are equal.
Certainly, these two operations are very useful, however, when you search on a search engine or in a database you often make spelling mistakes. An effective program must at least allow us to correct the situation and to realize our error.

Several distances exist to find the similarity between two strings. The most known for strings of the same length is the hamming distance. It measures the minimum number of substitutions necessary to change one string to another or the minimum number of errors that could have transformed one string into another. It owes its name to the American mathematician Richard Hamming.

--

--

Adil Essannouni

I am Adil Essannouni passionate about sport and web development. I would like to share my modest experience with you