Click here to Skip to main content
13,148,260 members (59,480 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi i am working on MessageQueue.Enqueue..
Following is my code
string line;
System.IO.StreamReader file = new System.IO.StreamReader("c:\\test.txt");
while ((line = file.ReadLine()) != null)
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!

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

1 solution

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

Solution 1

Use String.Split[^] to break the lines into the parts on the "|" character:
string[] parts = line.Split('|');
Then (having checked you have enough parts)
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;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100