Click here to Skip to main content
14,661,186 members
Rate this:
Please Sign up or sign in to vote.
See more:
HI,

I have text file, it contain following text.

Starting Ping at
The current time is: 18:26:15.37
Enter the new time:
Pinging 192.168.1.143 with 32 bytes of data:
Reply from 192.168.1.143: bytes=32 time=12ms TTL=123
Reply from 192.168.1.143: bytes=32 time=12ms TTL=123
Reply from 192.168.1.143: bytes=32 time=12ms TTL=123
Reply from 192.168.1.143: bytes=32 time=12ms TTL=123
Ping statistics for 192.168.1.143:
    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#
Posted
Updated 28-Aug-12 17:51pm
v2
Comments
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..

Rate this:
Please Sign up or sign in to vote.

Solution 2

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);
       break;
    }
 }
 file.Close();
 Console.WriteLine(finalString);
 Console.ReadLine();
   
v3
Comments
Soft009 29-Aug-12 3:07am
   
Thanks a lot... I'll try this.
Rate this:
Please Sign up or sign in to vote.

Solution 1

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100