StringWriter.Write 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将数据写入字符串。
重载
| 名称 | 说明 |
|---|---|
| Write(Char[], Int32, Int32) |
将字符的子数组写入字符串。 |
| Write(String) |
将字符串写入当前字符串。 |
| Write(StringBuilder) |
将字符串生成器的字符串表示形式写入当前字符串。 |
| Write(Char) |
将字符写入字符串。 |
| Write(ReadOnlySpan<Char>) |
将字符范围的字符串表示形式写入当前字符串。 |
Write(Char[], Int32, Int32)
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
将字符的子数组写入字符串。
public:
override void Write(cli::array <char> ^ buffer, int index, int count);
public override void Write(char[] buffer, int index, int count);
override this.Write : char[] * int * int -> unit
Public Overrides Sub Write (buffer As Char(), index As Integer, count As Integer)
参数
- buffer
- Char[]
要从中写入数据的字符数组。
- index
- Int32
缓冲区中开始读取数据的位置。
- count
- Int32
要写入的最大字符数。
例外
buffer 是 null。
index 或 count 为负数。
(index + count)>buffer.
Length。
写入器已关闭。
示例
此代码示例是为构造函数提供的大型示例的 StringWriter() 一部分。
// Use the three overloads of the Write method that are
// overridden by the StringWriter class.
strWriter.Write("file path characters are: ");
strWriter.Write(
Path.InvalidPathChars, 0, Path.InvalidPathChars.Length);
strWriter.Write('.');
' Use the three overloads of the Write method that are
' overridden by the StringWriter class.
strWriter.Write("file path characters are: ")
strWriter.Write( _
Path.InvalidPathChars, 0, Path.InvalidPathChars.Length)
strWriter.Write("."C)
注解
此方法重写 TextWriter.Write。
此方法从count位置StringWriter开始向此buffer写入index数据的字符。
下表列出了其他典型或相关的 I/O 任务的示例。
| 执行此操作... | 请参阅本主题中的示例... |
|---|---|
| 创建文本文件。 | 如何:将文本写入文件 |
| 写入文本文件。 | 如何:将文本写入文件 |
| 从文本文件中读取。 | 如何:从文件读取文本 |
| 将文本追加到文件中。 |
如何:打开日志文件并将其追加到日志文件 File.AppendText FileInfo.AppendText |
| 获取文件的大小。 | FileInfo.Length |
| 获取文件的属性。 | File.GetAttributes |
| 设置文件的属性。 | File.SetAttributes |
| 确定文件是否存在。 | File.Exists |
| 从二进制文件读取。 | 如何:读取和写入新创建的数据文件 |
| 写入二进制文件。 | 如何:读取和写入新创建的数据文件 |
另请参阅
适用于
Write(String)
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
将字符串写入当前字符串。
public:
override void Write(System::String ^ value);
public override void Write(string value);
public override void Write(string? value);
override this.Write : string -> unit
Public Overrides Sub Write (value As String)
参数
- value
- String
要写入的字符串。
例外
写入器已关闭。
示例
该代码示例是 StringWriter 类中的一个较大示例的一部分。
convertedCharacter = (char)intCharacter;
if(convertedCharacter == '.')
{
strWriter.Write(".\n\n");
// Bypass the spaces between sentences.
strReader.Read();
strReader.Read();
}
convertedCharacter = Convert.ToChar(intCharacter)
If convertedCharacter = "."C Then
strWriter.Write("." & vbCrLf & vbCrLf)
' Bypass the spaces between sentences.
strReader.Read()
strReader.Read()
注解
此方法重写 TextWriter.Write。
如果指定的字符串为 null,则不写入任何内容。
下表列出了其他典型或相关的 I/O 任务的示例。
| 执行此操作... | 请参阅本主题中的示例... |
|---|---|
| 创建文本文件。 | 如何:将文本写入文件 |
| 写入文本文件。 | 如何:将文本写入文件 |
| 从文本文件中读取。 | 如何:从文件读取文本 |
| 将文本追加到文件中。 |
如何:打开日志文件并将其追加到日志文件 File.AppendText FileInfo.AppendText |
| 获取文件的大小。 | FileInfo.Length |
| 获取文件的属性。 | File.GetAttributes |
| 设置文件的属性。 | File.SetAttributes |
| 确定文件是否存在。 | File.Exists |
| 从二进制文件读取。 | 如何:读取和写入新创建的数据文件 |
| 写入二进制文件。 | 如何:读取和写入新创建的数据文件 |
另请参阅
适用于
Write(StringBuilder)
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
将字符串生成器的字符串表示形式写入当前字符串。
public:
override void Write(System::Text::StringBuilder ^ value);
public override void Write(System.Text.StringBuilder? value);
override this.Write : System.Text.StringBuilder -> unit
Public Overrides Sub Write (value As StringBuilder)
参数
- value
- StringBuilder
要写入字符串的字符串生成器。
适用于
Write(Char)
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
将字符写入字符串。
public:
override void Write(char value);
public override void Write(char value);
override this.Write : char -> unit
Public Overrides Sub Write (value As Char)
参数
- value
- Char
要写入的字符。
例外
写入器已关闭。
示例
此代码示例是为构造函数提供的大型示例的 StringWriter() 一部分。
// Use the three overloads of the Write method that are
// overridden by the StringWriter class.
strWriter.Write("file path characters are: ");
strWriter.Write(
Path.InvalidPathChars, 0, Path.InvalidPathChars.Length);
strWriter.Write('.');
' Use the three overloads of the Write method that are
' overridden by the StringWriter class.
strWriter.Write("file path characters are: ")
strWriter.Write( _
Path.InvalidPathChars, 0, Path.InvalidPathChars.Length)
strWriter.Write("."C)
注解
此方法重写 TextWriter.Write。
下表列出了其他典型或相关的 I/O 任务的示例。
| 执行此操作... | 请参阅本主题中的示例... |
|---|---|
| 创建文本文件。 | 如何:将文本写入文件 |
| 写入文本文件。 | 如何:将文本写入文件 |
| 从文本文件中读取。 | 如何:从文件读取文本 |
| 将文本追加到文件中。 |
如何:打开日志文件并将其追加到日志文件 File.AppendText FileInfo.AppendText |
| 获取文件的大小。 | FileInfo.Length |
| 获取文件的属性。 | File.GetAttributes |
| 设置文件的属性。 | File.SetAttributes |
| 确定文件是否存在。 | File.Exists |
| 从二进制文件读取。 | 如何:读取和写入新创建的数据文件 |
| 写入二进制文件。 | 如何:读取和写入新创建的数据文件 |
另请参阅
适用于
Write(ReadOnlySpan<Char>)
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
- Source:
- StringWriter.cs
将字符范围的字符串表示形式写入当前字符串。
public:
override void Write(ReadOnlySpan<char> buffer);
public override void Write(ReadOnlySpan<char> buffer);
override this.Write : ReadOnlySpan<char> -> unit
Public Overrides Sub Write (buffer As ReadOnlySpan(Of Char))
参数
- buffer
- ReadOnlySpan<Char>
要写入字符串的字符范围。