Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
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)
{
     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 11-Dec-12 22:51pm
v5
Comments
Kiran Susarla at 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
good
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;
    ...
    }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2014
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