如何从文本文件或文本框中查找特定单词 [英] how to find a particular word from text file or text box

查看:91
本文介绍了如何从文本文件或文本框中查找特定单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框.在第一个文本框中,假设我写了一个句子我的名字是Mayank",现在我想从第一个文本框中输入一个单词mayank,所以我在第二个文本框中编写了mayank,而不是单击查找"按钮.
我使用了该代码,但命名空间不起作用

Hi ,I have two text boxes.In first text box suppose i write a sentence "My name is Mayank" now i want a word mayank from first text box so i write mayank in second text box than click to Find button.
i used that code but namespace doesn''t work

//namespace DisplayWordJaNein



代码是-



and code is-

string txtfilesentence;
            string word;
            txtfilesentence = txtshowfile.Text;
            word = txtwordmatch.Text;

            if (string.Equals(txtfilesentence, word))
            {
                lblfound.Text = "word matched";
            }
            else
            {
                lblnotfound.Text = "word not matched";
            }


或如何使用另一个命名空间?


or how to use another namespace ?

推荐答案

将代码更改为此.
Change your code to this .. It will work

string txtfilesentence=string.Empty;
        string word=string.Empty;
        txtfilesentence = txtshowfile.Text.Trim();
        word = txtwordmatch.Text.Trim();
        if (txtfilesentence.Contains(word))
        {
            lblfound.Text = "word matched";
        }
        else
        {
            lblnotfound.Text = "word not matched";
        }



编辑



Edited


function findit(byRef TheText) as integer
dim i as integer
i=instr(RichTextBox1.text, TheText)
return i
end function


这篇关于如何从文本文件或文本框中查找特定单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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