469,645 Members | 1,197 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

StreamWriter.Write and WriteLine?

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
Nov 21 '05 #1
12 10663
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
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

Nov 21 '05 #2
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
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

Nov 21 '05 #3
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
Nov 21 '05 #4
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
Nov 21 '05 #5
"Nina" <Ni**@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
"Nina" <Ni**@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
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
"Chris, Master of All Things Insignifican" wrote:
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
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


Nov 21 '05 #8
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
"Chris, Master of All Things Insignifican" wrote:
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
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


Nov 21 '05 #9
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
"Nina" <Ni**@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com... 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
"Chris, Master of All Things Insignifican" wrote:
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
> 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


Nov 21 '05 #10
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
"Nina" <Ni**@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com... 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
"Chris, Master of All Things Insignifican" wrote:
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
> 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


Nov 21 '05 #11
Thank you Jay.

Nina

"Jay B. Harlow [MVP - Outlook]" wrote:
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
"Nina" <Ni**@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
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
"Chris, Master of All Things Insignifican" wrote:
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
> 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


Nov 21 '05 #12
Thank you Jay.

Nina

"Jay B. Harlow [MVP - Outlook]" wrote:
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
"Nina" <Ni**@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
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
"Chris, Master of All Things Insignifican" wrote:
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" <Ni**@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
> 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


Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Nina | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.