检查文本框中的数据与记事本中的单词列表匹配 [英] what to check data in text box is matching with list of words in notepad

查看:79
本文介绍了检查文本框中的数据与记事本中的单词列表匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我正在做一个属于我自己的项目。我希望如果在文本框中输入文本,则应根据记事本中的单词列表进行检查。

1 )如何将记事本附加到我们的项目中。

2)如何根据记事本中的单词列表检查单词。

请帮助先生。

解决方案

只需将文本文件拖放到Visual Studio解决方案资源管理器中即可将文本文件附加到项目中。



为了阅读文件的内容,您可以使用 File.ReadLines [ ^ ]方法。那将为您提供一个字符串列表,您可以使用它来匹配文本框中的数据


您不能(或者至少你真的,真的不应该)尝试使用外部EXE作为应用程序中的编辑框 - 您应该考虑使用嵌入到应用程序中的TextBox或RichTextBox控件。

这样,您可以访问它的文本内容而不会出现任何问题 - 它只是控件的一个属性 - 你不必依赖你的用户使用记事本(或者甚至已经安装了它 - 用不太好的东西替换它并不困难,只要你的应用程序是非常不同的有关。


  //  此代码优先逐个阅读文本文件中的单词, 
// 保存在记事本文件中像每行一个字

int aCounter = 0 ; string aWordInTextFile;
// 读取文件并逐行显示。
系统。 IO.StreamReader file = new System.IO.StreamReader( C:\\\
otePadFile.txt);
while ((aWordInTextFile = file.ReadLine())!= null ){
Console.WriteLine(aWordInTextFile);
if (textbox.text == aWordInTextFile){
messagebox.show( 字符串匹配,在记事本文件中找到一个字符串);
}
aCounter ++;

}

file.Close();

// 暂停屏幕。
Console.ReadLine( );


sir i am doing a project of my own.in that i want if a entered a text in textbox it should be check against a list of words in the notepad.my quaries are.
1)how to attach a notepad to our project.
2)how to check the word against the list of words in the note pad.
please help sir.

解决方案

You can attach the text file to the project just by dragging it into the Visual studio solution explorer.

In order to read the content of the file you can use File.ReadLines[^] method. That would get you a list of string that you can use for matching the data in the textbox


You can't (or at least you really, really shouldn't) be trying to use an external EXE as a "editing box" in app - you should instead consider either using a TextBox or RichTextBox control embedded into your application.
That way, you can access it's text content with no problems at all - it's just a property of the control - and you don't have to rely on your user using notepad (or even having it installed - it's not difficult to replace with something better that works very, very differently as far as your application would be concerned.


//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();


这篇关于检查文本框中的数据与记事本中的单词列表匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆