本文介绍了从文本文件中搜索项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在C上有一个文本文件://file.txt



在该文本文件中包含 -



CodeProject

Coogle

代码

Cripsy

Cyclone

Crime

罪犯



Din

完成



值班

桌子



耳朵



.. .....







现在我的问题是 -

我有一个csharp winform应用程序

Button1

Textbox1

Listbox1



我想在按钮1上放一个代码 -

如果我在textbox1中写= E

在列表框中显示所有Word都是以file.txt中的E开头

如果我输入Do

然后显示

完成









怎么做?



感谢高级

Suppose I have a textfile on C://file.txt

On that text file contains -

CodeProject
Coogle
Code
Cripsy
Cyclone
Crime
Criminal
Dog
Din
Done
Doing
Duty
Desk
Eagle
Ear
Eat
.......

etc

Now my question is -
I have a csharp winform application
Button1
Textbox1
Listbox1

I wanna put a code on button1-
If I write in textbox1= E
On listbox show all Word started with E from file.txt
If I type "Do"
then show
Done
Doing
Dog


How to do this?

Thanks in advanced

推荐答案



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;
        }
        }
    }


这篇关于从文本文件中搜索项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 20:36
查看更多