Click here to Skip to main content
14,733,453 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
<pre><code></code>
Posted
Updated 14-Jul-17 9:41am
Comments
Amir Mahfoozi 19-Dec-11 5:21am
   
Some people are such experts that even with an empty question they have an answer to mention ! :)

How you do this will depend on a number of factors: since you haven't tried to explain in any detail, I'll assume you know nothing, and just give you the basics.

The easiest way to do this is to read the text file into a single string, and then use the .NET framework to find the match:
Dim text As String = File.ReadAllText("D:\Temp\MyFile.txt")
Dim index As Integer = text.IndexOf("hello")
If index >= 0 Then
   ' String is in file, starting at character "index"
End If

There are other ways, but that is pretty much the simplest.
   
Comments
koolprasadd 19-Dec-11 4:55am
   
Easy way OriginalGriff. 5.
You need StreamReader and Regx for that.

//read file content in StreamReader
StreamReadertxt Reader = new StreamReader(fName);
szReadAll = txtReader.ReadToEnd();//Reads the whole text file to the end
txtReader.Close(); //Closes the text file after it is fully read.
txtReader = null;
//search word in file content
if (Regex.IsMatch(szReadAll, "SearchME", RegexOptions.IgnoreCase))//If the match is found in allRead
  MessageBox.Show("found");
else
  MessageBox.Show("not found");
   
Comments
OriginalGriff 19-Dec-11 4:51am
   
Using a regex is a bit of a big sledgehammer to crack a really quite small nut.
As is using a stream reader to fetch the data...
Why would you need Regex? All you need is a streamreader


Dim Findstring = IO.File.ReadAllText("Your File Path")
Dim Lookfor as string = "hello"

If FindString.Contains(Lookfor) then
Msgbox("Found: " & Lookfor)
end if



Although... Your method would be cleaner and probably better for future use.. You don't need Regex.
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900