且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从文本文件中搜索项目

更新时间:2023-02-20 10:56:22

框架轻轻提供String.StartsWith方法 [ ^ ]。



在一个天真的方法中,你逐行阅读文件并使用建议的方法,如果匹配,那么你将读取的单词添加到列表框。



在更聪明的方法中你可以将整个文件读入内存(例如,一组字符串)然后搜索到这样的缓存信息。
The framework gently provides the String.StartsWith method[^].

In a naive approach you read line by line the file and use the suggested method, if there is match then you add the read word to the list box.

In amore smart approach you could read the whole file once into memory (e.g. in a collection of strings) and then search into such cached info.


读取文本文件的项目并在列表< string>()$中添加这些项目c $ c>。对于其他工作,请遵循以下步骤:

保持自动完成列表打开 [ ^ ]
Read the items of textfile and add those items in a List<string>().For rest of the work follow this one:
Keep AutoComplete List Open[^]


protected void Button_Click(object sender, EventArgs e)
    {
        string fileLoc = Server.MapPath("You Location");
        if (File.Exists(fileLoc))
        {
            String line;
            using (TextReader tr = new StreamReader(fileLoc))
            {
                line = tr.ReadToEnd();
            }
           string[] read=line.StartsWith(textboxName.text);
        for(int i=0;i<read.length;i++)
        {
            //your logic;
        }
        }
    }