Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am working on MessageQueue.Enqueue..
Following is my code
C#
string line;
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");
while ((line = file.ReadLine()) != null)
{
     MessageQueue.Enqueue(line);
}

ProcessMsg(sender, e);

Now, i want to compare values of first line with Next Line, which will come after compiling first line.
if Suppose My first Line is...
|12:05:41.555 | Hand No.-1 | Code

And Second Line is...
|12:05:41.850 | Hand No.-1 | Project

so here basically I want to calculate the time difference of First line first column value with another line first column value in seconds or minute whatever!
Thanks...

Note: First column values in "hh:mm:ss.fff" format.
Posted
v5
Comments
Kiran Susarla 12-Dec-12 4:25am    
What is ProcessMsg method doing here and what are the values of sender and e?

1 solution

Use String.Split[^] to break the lines into the parts on the "|" character:
C#
string[] parts = line.Split('|');
Then (having checked you have enough parts)
C#
string s = "|12:05:41.555 | Hand No.-1 | Code";
string[] parts = s.Split('|');
DateTime time;
if (DateTime.TryParseExact(parts[1], "HH:mm:ss.fff ", CultureInfo.InvariantCulture, DateTimeStyles.None, out time))
    {
    TimeSpan diff = otherTime - time;
    ...
    }
 
Share this answer
 

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