StreamWriter.Write和WriteLine? [英] StreamWriter.Write and WriteLine?

查看:562
本文介绍了StreamWriter.Write和WriteLine?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

使用

StreamWriter的Write或WriteLine方法,一行可以在文本文件中保存的最大长度是多少?如果字符串太长而无法保存一个

行,那么Write或WriteLine会做什么?为了让我以后从文本文件中正确检索数据

,我必须知道正确的索引。对于

后面的代码,如果str1的长度超过文本文件中的一行,那么在阅读文本文件时如何获得

str2'的索引?有没有办法处理这种

的情况?


///

dim sw as streamwriter

dim str1,str2 as string

sw.WriteLine(str1)

sw.WriteLine(str2)

\\ \\ /

感谢您的帮助。


Nina

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

推荐答案

我可能会误解你的问题,所以如果我不理我。如果文件无法处理要写入的

行的长度,那么询问WriteLine会做什么。

我不认为这会发生。文本文件中的一行是

只是CRLF的第一个实例。如果没有CRLF,则就StreamReader而言,该行永远不会结束。你能解释一个实例

这个字符串是否太长而无法存放?


Chris

" Nina" <镍** @ discussions.microsoft.com>在消息中写道

新闻:11 ********************************** @ microsof t.com ...
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...
你好,

使用StreamWriter的Write或一行,文本文件中一行可以容纳的最大长度是多少WriteLine方法?如果字符串太长而无法保留一行
,那么Write或WriteLine会做什么?为了让我以后从文本文件中正确检索数据,我必须知道正确的索引。对于
下面的代码,如果str1的长度超过文本文件中的一行,我怎样才能在读取文本文件时获得str2'的索引?有什么方法可以处理这种情况吗?
///
dim sw as streamwriter
dim str1,str2 as string
sw。 WriteLine(str1)
sw.WriteLine(str2)
\\\

我感谢你的帮助。

Nina
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



我可能会误解你的问题,所以如果我不理我。如果文件无法处理要写入的

行的长度,那么询问WriteLine会做什么。

我不认为这会发生。文本文件中的一行是

只是CRLF的第一个实例。如果没有CRLF,则就StreamReader而言,该行永远不会结束。你能解释一个实例

这个字符串是否太长而无法存放?


Chris

" Nina" <镍** @ discussions.microsoft.com>在消息中写道

新闻:11 ********************************** @ microsof t.com ...
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...
你好,

使用StreamWriter的Write或一行,文本文件中一行可以容纳的最大长度是多少WriteLine方法?如果字符串太长而无法保留一行
,那么Write或WriteLine会做什么?为了让我以后从文本文件中正确检索数据,我必须知道正确的索引。对于
下面的代码,如果str1的长度超过文本文件中的一行,我怎样才能在读取文本文件时获得str2'的索引?有什么方法可以处理这种情况吗?
///
dim sw as streamwriter
dim str1,str2 as string
sw。 WriteLine(str1)
sw.WriteLine(str2)
\\\

我感谢你的帮助。

Nina
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



Nina,


除了Chris,


这绝不会失败只要有足够的空间来进行灭绝,你就可以写它了,并且去除它也没有问题

(电源故障,线路故障或其他)。


您正在编写两个正确结束的字符串(否则您之前已经错误地将
错误)发送到同一个文件。


假设字符串和streamwriter都不是这个

的情况。


Cor
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


这篇关于StreamWriter.Write和WriteLine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆