What's Here?
- Members: 300,308
- Replies: 825,514
- Topics: 137,361
- Snippets: 4,417
- Tutorials: 1,147
- Total Online: 2,102
- Members: 127
- Guests: 1,975
|
Searches a text file for a string by using Regex.IsMatch
|
Submitted By: marcells23
|
|
Rating:
 
|
|
Views: 25,446 |
Language: C#
|
|
Last Modified: September 19, 2007 |
|
Instructions: input the path to the text file and the string to search for. |
Snippet
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace searchTxtFile
{
class searchTxt
{
static void Main()
{
string fName = @" ";//path to text file
StreamReader testTxt = new StreamReader (fName );
string allRead = testTxt.ReadToEnd();//Reads the whole text file to the end
testTxt.Close(); //Closes the text file after it is fully read.
string regMatch = " ";//string to search for inside of text file. It is case sensitive.
if (Regex.IsMatch(allRead,regMatch))//If the match is found in allRead
{
Console.WriteLine("found\n");
}
else
{
Console.WriteLine("not found\n");
}
}
}
}
Copy & Paste
|
|
|
|