I require help to search a text file (log file) using c# and display the line number and the complete line that contains the search keyword.
views:
646answers:
2
+1
A:
This is a slight modification from: http://msdn.microsoft.com/en-us/library/aa287535%28VS.71%29.aspx
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
if ( line.Contains("word") )
{
Console.WriteLine (counter.ToString() + ": " + line);
}
counter++;
}
file.Close();
Pessimist
2010-03-13 08:17:38
thanks optimist :)
Chitresh
2010-03-13 08:50:04
Now can you guide me how can i export the same to excel.i.e. line and line number
Chitresh
2010-03-13 09:02:02
Hm... you want the line number in one cell, and the actual line in another? If so, instead of separating by the colon there (on ": "), separate them by comma (",") and then have Excel read that as a CSV file (comma-separated value).
Pessimist
2010-03-13 09:11:45
no i need to built the functionality in the app itself to be able to export to excel... (requirements are such) .. please help
Chitresh
2010-03-13 09:47:44
That I don't know how to do. I'd search the web for c# export excel or I'd open a new question about that.
Pessimist
2010-03-13 10:38:25
ok thanks.. please keep me updated on this...
Chitresh
2010-03-13 11:03:32
A:
i have a project: " create index index on a text file, for creating an index, the user will be requried to specify the name of the file on which the index needs to be created and the name of the index file. if index has already been created on a file, a user should not be required to create it again the next time an operation is to performed on the file.. and load the files by index file i'm learn programming in C#, 3 months ago this project required write in windowapplication. help me! thanks so much
nguyen phuoc duy
2010-07-06 21:12:34