Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use the <a href="http://en.wikipedia.org/wiki/Levenshtein_distance" rel="noreferrer">Levenshtein Distance algorithm</a>. </p> <p><em>"The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character."</em> - Wikipedia.com</p> <p>This one is from <a href="http://dotnetperls.com/levenshtein" rel="noreferrer">dotnetperls.com</a>:</p> <pre><code>using System; /// &lt;summary&gt; /// Contains approximate string matching /// &lt;/summary&gt; static class LevenshteinDistance { /// &lt;summary&gt; /// Compute the distance between two strings. /// &lt;/summary&gt; public static int Compute(string s, string t) { int n = s.Length; int m = t.Length; int[,] d = new int[n + 1, m + 1]; // Step 1 if (n == 0) { return m; } if (m == 0) { return n; } // Step 2 for (int i = 0; i &lt;= n; d[i, 0] = i++) { } for (int j = 0; j &lt;= m; d[0, j] = j++) { } // Step 3 for (int i = 1; i &lt;= n; i++) { //Step 4 for (int j = 1; j &lt;= m; j++) { // Step 5 int cost = (t[j - 1] == s[i - 1]) ? 0 : 1; // Step 6 d[i, j] = Math.Min( Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost); } } // Step 7 return d[n, m]; } } class Program { static void Main() { Console.WriteLine(LevenshteinDistance.Compute("aunt", "ant")); Console.WriteLine(LevenshteinDistance.Compute("Sam", "Samantha")); Console.WriteLine(LevenshteinDistance.Compute("flomax", "volmax")); } } </code></pre> <p>You may in fact prefer to use the <a href="http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance" rel="noreferrer">Damerau-Levenshtein distance algorithm</a>, which also allows characters to be transposed, which is a common human error in data entry. You'll find a C# implementation of it <a href="http://mihkeltt.blogspot.com/2009/04/dameraulevenshtein-distance.html" rel="noreferrer">here</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload