By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 2,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

can i get next ReadLine Value of currentStr

P: n/a
what i know is...

while ((currentStr = sr.ReadLine()) != null)
{
in this area,
can i get next ReadLine Value of currentStr

}

best regard,,

Dec 1 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Not with that sort of construct.

If you want to deal with 2 lines at a time then you need to do it slightly
differently, something like:

string _line1 = sr.ReadLine();
while (_line1 != null)
{
string _line2 = sr.ReadLine();
if (_line2 == null) break;
// you now have both lines in memory
// do some stuff with them
string _line1 = sr.ReadLine();
}

If you to deal with 1 line at a time but you need to reference something in
the subsequent line then you need to do it slightly differently again,
something like:

string _line1 = sr.ReadLine();
while (_line1 != null)
{
string _line2 = sr.ReadLine();
if (_line2 == null) break;
// you now have both lines in memory
// do some stuff with them
_line1 = _line2;
}
"PointMan" <so**********@gmail.comwrote in message
news:uM*************@TK2MSFTNGP04.phx.gbl...
what i know is...

while ((currentStr = sr.ReadLine()) != null)
{
in this area,
can i get next ReadLine Value of currentStr

}
best regard,,

Dec 1 '06 #2

P: n/a
thank you for your reply
it helps to me...but i still have some problems...
if Data is 12345,

while ((currentStr = sr.ReadLine()) != null)
{
if((nextStr = sr.ReadLine()) != null);

wanna read like below
currentStr = sr.ReadLine() - read 1
nextStr = sr.ReadLine()- read 2
currentStr = sr.ReadLine()- read 2
nextStr = sr.ReadLine()- read 3

how can i solve this.,.
"Stephany Young" <noone@localhostwrote in message
news:Ob**************@TK2MSFTNGP04.phx.gbl...
Not with that sort of construct.

If you want to deal with 2 lines at a time then you need to do it slightly
differently, something like:

string _line1 = sr.ReadLine();
while (_line1 != null)
{
string _line2 = sr.ReadLine();
if (_line2 == null) break;
// you now have both lines in memory
// do some stuff with them
string _line1 = sr.ReadLine();
}

If you to deal with 1 line at a time but you need to reference something
in the subsequent line then you need to do it slightly differently again,
something like:

string _line1 = sr.ReadLine();
while (_line1 != null)
{
string _line2 = sr.ReadLine();
if (_line2 == null) break;
// you now have both lines in memory
// do some stuff with them
_line1 = _line2;
}
"PointMan" <so**********@gmail.comwrote in message
news:uM*************@TK2MSFTNGP04.phx.gbl...
>what i know is...

while ((currentStr = sr.ReadLine()) != null)
{
in this area,
can i get next ReadLine Value of currentStr

}
best regard,,

Dec 1 '06 #3

P: n/a
I get the impression that you don't really understand what your loop is
really doing.

What 'while ((currentStr = sr.ReadLine()) != null)' is doing is: Start at
the beginning of the file and read each line in turn into currentStr until
there are no more lines.

At the beginning of the loop, the 'pointer is at the beginning of the first
line. Each time you execute sr.ReadLine(), the line beginning at the
'pointer' is read and the 'pointer' is advanced to the beginning of the next
line.

It would appear that you think that you can use sr.ReadLine() to read some
arbitrary text from somewhere.

You need to clearly define what your goal is and then use the appropriate
techniques to achieve it.

"PointMan" <so**********@gmail.comwrote in message
news:u2**************@TK2MSFTNGP06.phx.gbl...
thank you for your reply
it helps to me...but i still have some problems...
if Data is 12345,

while ((currentStr = sr.ReadLine()) != null)
{
if((nextStr = sr.ReadLine()) != null);

wanna read like below
currentStr = sr.ReadLine() - read 1
nextStr = sr.ReadLine()- read 2
currentStr = sr.ReadLine()- read 2
nextStr = sr.ReadLine()- read 3

how can i solve this.,.
"Stephany Young" <noone@localhostwrote in message
news:Ob**************@TK2MSFTNGP04.phx.gbl...
>Not with that sort of construct.

If you want to deal with 2 lines at a time then you need to do it
slightly differently, something like:

string _line1 = sr.ReadLine();
while (_line1 != null)
{
string _line2 = sr.ReadLine();
if (_line2 == null) break;
// you now have both lines in memory
// do some stuff with them
string _line1 = sr.ReadLine();
}

If you to deal with 1 line at a time but you need to reference something
in the subsequent line then you need to do it slightly differently again,
something like:

string _line1 = sr.ReadLine();
while (_line1 != null)
{
string _line2 = sr.ReadLine();
if (_line2 == null) break;
// you now have both lines in memory
// do some stuff with them
_line1 = _line2;
}
"PointMan" <so**********@gmail.comwrote in message
news:uM*************@TK2MSFTNGP04.phx.gbl...
>>what i know is...

while ((currentStr = sr.ReadLine()) != null)
{
in this area,
can i get next ReadLine Value of currentStr

}
best regard,,


Dec 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.