Hello I think that the LevenshteinDistance algorithm could be the solution to your problem. let me explain:
the default implementation of the algorithm:
static class LevenshteinDistance
{
public static int Compute(string s, string t)
{
int n = s.Length;
int m = t.Length;
int[,] d = new int[n + 1, m + 1];
if (n == 0)
{
return m;
}
if (m == 0)
{
return n;
}
for (int i = 0; i <= n; d[i, 0] = i++)
{
}
for (int j = 0; j <= m; d[0, j] = j++)
{
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
int cost = (t[j - 1] == s[i - 1]) ? 0 : 1;
d[i, j] = Math.Min(
Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1),
d[i - 1, j - 1] + cost);
}
}
return d[n, m];
}
}
next a simple button with some kind of logic:
private void button1_Click(object sender, EventArgs e)
{
string baseString = "Basic";
List<string> lstStringsToCheck = new List<string>
{
"Bas",
"Test",
"Prod",
"Basist",
"Bar",
"Result",
"Another string"
};
Dictionary<string,int> resultset = new Dictionary<string, int>();
foreach (string stringtoTest in lstStringsToCheck)
{
resultset.Add(stringtoTest,LevenshteinDistance.Compute(baseString, stringtoTest));
}
int minimumModifications = resultset.Min(c=>c.Value);
var closestlist = resultset.Where(c => c.Value == minimumModifications);
}
as you can see I start with a baseString. this is in your example "harlishr". next I create a list with all possible strings.
further I've created a dictionary where I'll save the result from the LevenshteinDistance.compute method.
foreach string in my list I compute the distance and add this to the result dictionary.
afterwards I take the minimum value.
I select all the results that have this minimum value (this is the string or list of strings that is/are the closest to the original)
hope this helps
Kind regards