What's Here?
- Members: 244,274
- Replies: 693,119
- Topics: 113,158
- Snippets: 3,863
- Tutorials: 935
- Total Online: 1,153
- Members: 74
- Guests: 1,079
|
Searches a text file for a string by using Regex.IsMatch
|
Submitted By: marcells23
|
|
Rating:
 
|
|
Views: 19,964 |
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
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|