What's Here?
- Members: 109,556
- Replies: 414,462
- Topics: 63,029
- Snippets: 2,288
- Tutorials: 611
- Total Online: 1,345
- Members: 60
- Guests: 1,285
Who's Online?
|
Welcome to Dream.In.Code |
|
|
Getting C# Help is Easy!
Join 109,556 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,345 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
Searches a text file for a string by using Regex.IsMatch
|
Submitted By: marcells23
|
|
Rating:
  
|
|
Views: 7,352 |
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
|