473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

Similar topics

1
by: Daniel | last post by:
Is there any way for System.IO.StreamWriter Write method to write out part of the string to file. such as if the machine is shut down half way through? or does the file not actually exist until the...
2
by: Daniel | last post by:
if System.IO.StreamWriter write throws an exception, is there anyway to close the System.IO.StreamWriter object? it seems to stay open when this happens then future attempts to write to that same...
9
by: John | last post by:
Hi, I need to write out bits that I receive from another process. These are boolean values. I need there to be 8 bits in every byte. I know I could write these bits out as char's using one bit...
1
by: Daniel | last post by:
If my System.IO.StreamWriter Write method throws "The specified network name is no longer available." and I try to Dispose or Close it in the finaly clause the close or dispose method just throws...
5
by: xuxu | last post by:
If you use StreamWrite Write or WriteLine it causes Session to End! e.g. FileStream fs = File.Open(fileName,FileMode.Append,FileAccess.Write); StreamWriter sw = new StreamWriter(fs);...
0
by: Nina | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.