I am programming a program to search for a name from a list, and I need to find them even if the keyword is not in front of the names (which I do not mean the prefix)
for example , if I use a list of musical instruments and I type “guit” in the search text box. He should find the names "Guitar, Guitarrón, Acoustic Guitar, Bass Guitar, ..."
or something like this sentence of the Longdo dictionary .
here is my simple and dumb algorithm (that's all i can do)
const int SEARCHROWLIMIT = 30;
private string[] DoSearch(string Input, string[] ListToSearch)
{
List<string> FoundNames = new List<string>();
int max = 0;
bool over = false;
for (int k = 0; !over; k++)
{
foreach (string item in ListToSearch)
{
max = (max > item.Length) ? max : item.Length;
if (k > item.Length) continue;
if (k >= max) { over = true; break; }
if (!Input.Equals("Search")
&& item.Substring(k, item.Length - k).StartsWith(Input, StringComparison.OrdinalIgnoreCase))
{
bool exist = false;
int i = 0;
while (!exist && i < FoundNames.Count)
{
if (item.Equals(FoundNames[i]))
{
exist = true;
break;
}
i++;
}
if (!exist && FoundNames.Count < SEARCHROWLIMIT)
FoundNames.Add(item);
else if (FoundNames.Count >= SEARCHROWLIMIT) over = true;
}
}
}
return FoundNames.ToArray();
}
, , SEARCHROWLIMIT,
, , .
, , , ,... . .
?