在文本文件中找到下一个单词? [英] Find next word in text file?

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

问题描述

朋友,

当我单击搜索按钮时,我有一个文本框和一个搜索按钮,它与文本文件中的文本框文本匹配,如果文本匹配,则它在消息框或标签中显示下一个单词.

我该怎么办?

现在我正在使用下面的代码,该代码可以帮助匹配文本字段中的文本框值,但是我如何才能从文本文件中获取下一个单词呢,有人可以帮助我吗?

Hi Friends,

I have an textbox and an search button when i am click on search button its match the textbox text in text file and if text is match then its show next word in the messagebox or label.

how i can do this thing?

right now i am using the follwing code which is help to match the textbox value in the textfield but how i can got the next word form the text file can any one help me??

Dim InputStr As String = SearchTextbox.Text
       For Each FileStr As String In IO.Directory.GetFiles("D:\", "*.txt")
           If IO.File.ReadAllText(FileStr).IndexOf(InputStr) >= 0 Then


               'SearchTextbox.Text = IO.File.ReadAllText(InputStr)

               MessageBox.Show("Text Match Dome.", "Text Match", MessageBoxButton.OK, MessageBoxImage.Information)
           End If
       Next

推荐答案

没有您的if运算符,请将ReadAllText的结果分配给某个字符串变量,然后对其进行解析以获取所需的内容.以System.String.Split开头:
http://msdn.microsoft.com/en-us/library/system.string. split.aspx [^ ].

—SA
Without your if operator, assign the result of ReadAllText to some string variable and parse it to get what you need. Start with System.String.Split:
http://msdn.microsoft.com/en-us/library/system.string.split.aspx[^].

—SA


这是我使用的代码..

Here is the code that i used..

Dim fileAs String = Application.StartupPath & "\file.txt"

      If System.IO.File.Exists(file.txt) = True Then
          Dim objReader As New System.IO.StreamReader(file.txt)
          file= objReader.ReadToEnd

         ' Or you can use objReader.ReadLine '
      Else
          MsgBox("File does not exists")
          Exit Sub
      End If


这篇关于在文本文件中找到下一个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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