我正在编程一个程序来搜索列表中的名称,即使关键字不在名称前面我也需要找到它们(这就是我的意思是非前缀)
例如,如果我的列表是乐器,我在搜索文本框中键入"guit".
它应该找到名称"吉他,Guitarrón,原声吉他,低音吉他,......"
或类似Longdo Dictionary的搜索建议.
这是我简单而愚蠢的算法(这就是我所能做的)
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")
&& …Run Code Online (Sandbox Code Playgroud)