What's Here?
- Members: 95,475
- Replies: 379,757
- Topics: 56,731
- Snippets: 1,915
- Tutorials: 494
- Total Online: 956
- Members: 34
- Guests: 922
Who's Online?
|
Searches a text file for a string by using Regex.IsMatch
|
Submitted By: marcells23
|
|
Rating:
  
|
|
Views: 5,405 |
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
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|