Hello everybody!
I want to find a string in the txt file. Example I have a file .File Name is test.txt and data in this file has "Hello Everybody . I am Toan" . And I enter a string "I am" ,the result will return "true" because the file constains the string. I am using C#. Can you help me to do it? Thanks very much
Loading
Sam HobbsPosted Apr 7, 2012, 8:52 PM
toanhoi buiPosted Apr 6, 2012, 11:34 PM
Satyapriya NayakPosted Apr 6, 2012, 11:02 PM
Try this...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace search
{
class Program
{
static void Main(string[] args)
{
string fName = @"D:\test.txt";
StreamReader testTxt = new StreamReader(fName);
string allRead = testTxt.ReadToEnd();
testTxt.Close();
string regMatch = "I am";
if (Regex.IsMatch(allRead,regMatch))
{
Console.WriteLine("True:Found\n");
}
else
{
Console.WriteLine("False:Not found\n");
}
Console.ReadLine();
}
}
}
Thanks
If this post helps you mark it as answer