TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sophistLady
NA
1
0
Read two text files
Oct 7 2006 1:34 AM
Hi,
I need to read from 2 text files. Here is my logic.
1) Read first line of Text1.
2) Compare with every line in Text2.
3) Read second line of Text1.
4) Compare with every line in Text2.
and so on..till it reach the last line of Text1.
Sample data in Text 1:
TimeWritten
2006-10-05 03:01:39
2006-10-05 12:02:40
2006-10-05 17:54:58
Sample data in Text 2:
TimeWritten
2006-10-05 03:00:49
2006-10-05 03:05:49
2006-10-05 03:06:49
2006-10-05 12:02:49
2006-10-05 12:03:49
2006-10-05 12:04:49
2006-10-05 12:05:49
2006-10-05 12:06:49
2006-10-05 17:53:58
Below is my codes. But my problem is, when it is reading the 2nd line of Text1, it doesn't compare with Text2 anymore.
public void readText()
{
string strPath;
strPath = AppDomain.CurrentDomain.BaseDirectory;
StreamReader sr = new StreamReader(strPath + "recycle.txt");
StreamReader sr2 = new StreamReader(strPath + "objectRef.txt");
//Read the 1st line of recycle.txt
string line = sr.ReadLine();
//Read the 2nd line of recycle.txt
line = sr.ReadLine();
//Read the 1st line of objectRef.txt
string line2 = sr2.ReadLine();
//Read the 2nd line of objectRef.txt
line2 = sr2.ReadLine();
//declare variables
string StartRecycleTime;
DateTime EndRecycleTime;
string ObjectRefTime;
while (line != null)
{
//recycle time (start)
StartRecycleTime = line.Substring(11,8);
//recycle time (end)
EndRecycleTime = (Convert.ToDateTime(StartRecycleTime)).AddMinutes(7.0);
//writing to console
Console.WriteLine("Recycle Time (start): " + StartRecycleTime);
Console.WriteLine("Recycle Time (end): " + EndRecycleTime.ToString("HH:mm:ss"));
//read objectRef.txt
while (line2 != null)
{
ObjectRefTime = line2.Substring(11,8);
if ((DateTime.Compare(Convert.ToDateTime(ObjectRefTime), Convert.ToDateTime(StartRecycleTime)) > 0) && (DateTime.Compare(Convert.ToDateTime(ObjectRefTime), Convert.ToDateTime(EndRecycleTime)) < 0))
{
Console.WriteLine("Object Ref: " + ObjectRefTime);
line2 = sr2.ReadLine();
}
else
{
line2 = sr2.ReadLine();
}
}
sr2.Close();
line = sr.ReadLine();
}
sr.Close();
Console.ReadLine();
}
Can anyone point out where is my mistake?
Thank you very much in advance..
Reply
Answers (
1
)
Very Urgent : Regarding sending the serialized object through sslstream.
List All Installed Applications On Local Machine by C#.NET