473,508 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can i get next ReadLine Value of currentStr

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
3 1797
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8688
by: peter leonard | last post by:
Hi, I having a problem with reading each line from a text file. For example, the file is a text file named 'test.txt' with the following content : line 1 line 2 line 3 line 4 line 5
12
53228
by: Mike Maxwell | last post by:
When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL .... abc a b c
19
10522
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to...
2
8448
by: Eddy | last post by:
I have a big problem with streamreader ReadLine()! I read from a long text files about 13k lines, than I encounter a problem: ReadLine() is not anymore able to go on! I have a string whose name is...
1
1436
by: t4zone58 | last post by:
Hi Basically I am print out a group of number with a certain increment. However I found out a wierd thing happened from the result The code I wrote: Dim number1, number2, counter, increment As...
5
3422
by: rodchar | last post by:
hey all, i'm trying to read a text document line by line into a stringbuilder and an issue i'm running into is this: do while streamReader.ReadLine stringBuilder.Append("my string" &...
4
1511
by: Vernon Wenberg III | last post by:
I'm not really sure how readline() works. Is there a way to iterate through a file with multiple lines and then putting each line in a variable in a loop?
5
2713
by: kj | last post by:
I'm trying to subclass file, overriding the readline method. The new method definition begins with def readline(self, size=None): line = self.file.readline(size) # etc., etc. ....where the...
0
2432
by: Akira Kitada | last post by:
Hi list, I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed to build some of the modules. """ Failed to find the necessary bits to build these modules: _bsddb ...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.