StreamWriter.Write and WriteLine?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

What is the maximum length that one line can hold in a text file using
StreamWriter's Write or WriteLine method? If the string is too long for one
line to hold, what will Write or WriteLine do? In order me to retrieve data
correctly from the text file later, I have to know the right index. For the
following code,if str1's length exceeds one line in text file, how can I get
str2's index when reading the text file? Is there any way to handle this
kind of situation?

///
dim sw as streamwriter
dim str1, str2 as string
sw.WriteLine(str1)
sw.WriteLine(str2)
\\\

I appreciate your help.

Nina
 
I may be misunderstanding your question, so ignore me if I am. You are
asking what WriteLine will do if the file can't handle the length of the
line to be written. I don't think this can happen. A line in a textfile is
just the first instance of CRLF. If there is not a CRLF then the line never
ends as far as the StreamReader is concerned. Can you explain an instance
that the string is too long for line to hold?

Chris
 
Nina,

In addition to Chris,

This will never fail as long as there is enough room in the destignation you
are writting it too, and the destignation has no problems receiving it
(power failures, line failures or whatever).

You are writing two strings which are ended correctly (otherwise you had
already an error before that) to the same file.

Assuming that the strings and streamwriter are not both Nothing as in this
case.

Cor
 
Nina said:
What is the maximum length that one line can hold in a text file using
StreamWriter's Write or WriteLine method? If the string is too long for
one
line to hold, what will Write or WriteLine do? In order me to retrieve
data
correctly from the text file later, I have to know the right index. For
the
following code,if str1's length exceeds one line in text file, how can I
get
str2's index when reading the text file? Is there any way to handle this
kind of situation?

An 'OutOfMemoryException' is thrown if the buffer for the line cannot be
allocated.
 
Sorry for not explaining clearly about the questions. Let me try to make it
as clear as I can here. For the code below, if str1 is about 50 English
words and write to a text file, when you open this text file using Notepad,
you can see str1 's text occupied several lines on the screen. Later when
you use streamreader.readline to read str1's text will it be in one line or
several lines, in other words will ReadLine method read the entire str1's
text ?

///
dim sw as streamwriter
dim str1, str2 as string
sw.WriteLine(str1)
sw.WriteLine(str2)
\\\

Thanks again.

Nina
 
Nina,
In addition to the other comments.

You can use "Format - Word Wrap" in Notepad to control if lines are wrapped
or not (if they occupy several lines on the screen).

Further in NotePad you can change the size of the window to change where the
lines wrap!
in other words will ReadLine method read the entire str1's
text ?
As the other have pointed out, the actual end of line is where the CRLF is,
so yes, as that is where the CRLF will be written!

Hope this helps
Jay
 
Thank you Jay.

Nina

Jay B. Harlow said:
Nina,
In addition to the other comments.

You can use "Format - Word Wrap" in Notepad to control if lines are wrapped
or not (if they occupy several lines on the screen).

Further in NotePad you can change the size of the window to change where the
lines wrap!

As the other have pointed out, the actual end of line is where the CRLF is,
so yes, as that is where the CRLF will be written!

Hope this helps
Jay
 
Back
Top