Hi !!!!!
i need to search for a string in a text file and at the same time i want store the perticular line containing search text into a string variable..
for eg..
i've line
1 abc technician
2 bbb new
if i search for 2 then it should go the line('2 bbb new ') and store entire line in a variable
How can i achieve this ????
Loading
Manikavelu VelayuthamPosted Sep 27, 2010, 5:59 AM
using System;
using System.IO;
namespace CSharpCorner
{
class Program
{
static void Main( string[] args )
{
string filePath = @"c:\temp\test.txt";
string line;
if (File.Exists( filePath ))
{
StreamReader file = null;
try
{
file = new StreamReader( filePath );
while ((line = file.ReadLine()) != null)
{
if (line.Contains("2"))
{
//do your matching code here
}
}
}
finally
{
if (file != null)
file.Close();
}
}
Console.ReadLine();
}
}
}