StringWriter.Write 方法

定义

将数据写入字符串。

重载

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

将字符的子数组写入字符串。

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

要写入的最大字符数。

例外

buffernull

indexcount 为负数。

(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( Char::Parse( "." ) );
// 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

此方法从 buffer位置 index开始将数据的字符写入countStringWriter

下表列出了其他典型或相关 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

将字符串写入当前字符串。

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 = Convert::ToChar( intCharacter );
if ( convertedCharacter == '.' )
{
   strWriter->Write(  ".\n\n" );
   
   // Bypass the spaces between sentences.
   strReader->Read();
   strReader->Read();
}
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

将字符串生成器的字符串表示形式写入当前字符串。

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

将字符写入字符串。

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( Char::Parse( "." ) );
// 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

将字符范围的字符串表示形式写入当前字符串。

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>

要写入字符串中的字符范围。

适用于