如何检查TextBox中输入的数据是否与记事本中的单词列表匹配

时间:2015-02-25 20:00:23

标签: c#

我正在自己做一个项目。我想检查TextBox控件中输入的文本是否与记事本中输入的单词列表匹配。

我的问题是:

  1. 如何将记事本附加到我的项目中?
  2. 如何根据记事本中找到的单词列表检查单词?
  3. 请指导我正确的方向。

2 个答案:

答案 0 :(得分:0)

您不需要将记事本附加到项目中,只需使用System.Io类打开它并阅读所有内容并使用比较方法检查字符串。

答案 1 :(得分:0)

//This code first read the words in text file one by one, 
//which are save in notepad file like one word per line 

int aCounter = 0; string aWordInTextFile;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader("c:\notePadFile.txt");
while((aWordInTextFile = file.ReadLine()) != null){
   Console.WriteLine (aWordInTextFile);
   if(textbox.text == aWordInTextFile){
        messagebox.show("String Match, found a string in notepad file");
   }
   aCounter++;

}

file.Close();

// Suspend the screen.
Console.ReadLine();