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
sabine
NA
11
0
Read all lines of a text file
Apr 4 2012 9:19 AM
Hi,
I'm using the below code to read a text file.
int counter = 0;
string readLine;
string accountName= "";
string contactFName = "";
string contactLName ="";
StreamReader tr = new StreamReader("text.txt");
// Read header
tr.ReadLine();
counter++;
while((readLine = tr.ReadLine()) != null)
{
tr.ReadLine();
readLine = readLine.Trim();
if (readLine == "") continue; // ignore blank lines
string[] items = readLine.Split(';');
accountName = items[0];
contactFName = items[1];
contactLName = items[2];
Console.WriteLine("attr1 = {0}, attr2 = {1}, attr3 = {2}, attr4 = {3}" + accountName + contactFName + contactLName);
counter++;
}
tr.Close();
I am having the header and two lines of data but the issue is that this code is reading only 1 line of data.
How can I make it loop on all the data lines?
Thank you in advance
Reply
Answers (
2
)
How to do that?
Split last word from the rest of the string