can i get next ReadLine Value of currentStr

  • Thread starter Thread starter PointMan
  • Start date Start date
P

PointMan

what i know is...

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

}

best regard,,
 
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;
}
 
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.,.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top