Click here to Skip to main content
14,732,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have text file, it contain following text.

Starting Ping at
The current time is: 18:26:15.37
Enter the new time:
Pinging with 32 bytes of data:
Reply from bytes=32 time=12ms TTL=123
Reply from bytes=32 time=12ms TTL=123
Reply from bytes=32 time=12ms TTL=123
Reply from bytes=32 time=12ms TTL=123
Ping statistics for
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 12ms, Maximum = 12ms, Average = 12ms

And here I need to extract the phase from the text file.
for an example I need to save time and the Minimum value.
like this 18:26:15.37 12ms

Is this possible to do in c#
Updated 28-Aug-12 18:51pm
virang_21 29-Aug-12 0:00am
yes it is possible..check System.IO.File .. read the file ... iterate throguth it line by line and look for your matching string..

It just headstart, you can improve further...
var finalString = string.Empty;
 var line = string.Empty;
 var file = new System.IO.StreamReader("c:\\text.txt");
 while ((line = file.ReadLine()) != null)
    if (line.Contains("The current time is:"))
       var strrr = Regex.Split(line, "The current time is: ");
       finalString = strrr[1];
    else if (line.Contains("Minimum ="))
       var strrr = Regex.Split(line, "Minimum =");
       finalString += strrr[1].Substring(0,5);
Soft009 29-Aug-12 3:07am
Thanks a lot... I'll try this.
You can use methods from the string class called Contains, Substring & IndexOf. Definetively you can use them all.

Hope it helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900