StringWriter.Write 方法

定义

将数据写入字符串。Writes data to the string.

重载

Write(Char[], Int32, Int32)

将字符的子数组写入字符串。Writes a subarray of characters to the string.

Write(String)

将字符串写入当前字符串。Writes a string to the current string.

Write(StringBuilder)

将字符串生成器的字符串表示形式写入当前字符串。Writes the string representation of a string builder to the current string.

Write(Char)

将字符写入字符串。Writes a character to the string.

Write(ReadOnlySpan<Char>)

将字符范围的字符串表示形式写入当前字符串。Writes the string representation of a span of chars to the current string.

Write(Char[], Int32, Int32)

将字符的子数组写入字符串。Writes a subarray of characters to the string.

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[]

要从中写出数据的字符数组。The character array to write data from.

index
Int32

缓冲区中开始读取数据的位置。The position in the buffer at which to start reading data.

count
Int32

要写入的最大字符数。The maximum number of characters to write.

例外

buffernullbuffer is null.

indexcount 为负数。index or count is negative.

(index + count)> buffer.(index + count)> buffer. Length.Length.

编写器已关闭。The writer is closed.

示例

此代码示例是为构造函数提供的更大示例的一部分 StringWriter()This code example is part of a larger example provided for the StringWriter() constructor.

// 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.WriteThis method overrides TextWriter.Write.

此方法 count StringWriter 从开始,将数据的字符写入到此 buffer indexThis method writes count characters of data to this StringWriter from buffer, starting at position index.

下表列出了其他典型或相关 i/o 任务的示例。The following table lists examples of other typical or related I/O tasks.

若要执行此操作...To do this... 请参见本主题中的示例...See the example in this topic...
创建文本文件。Create a text file. 如何:将文本写入文件How to: Write Text to a File
写入文本文件。Write to a text file. 如何:将文本写入文件How to: Write Text to a File
读取文本文件。Read from a text file. 如何:从文件中读取文本How to: Read Text from a File
向文件追加文本。Append text to a file. 如何:打开并追加到日志文件How to: Open and Append to a Log File

File.AppendText

FileInfo.AppendText
获取文件的大小。Get the size of a file. FileInfo.Length
获取文件的属性。Get the attributes of a file. File.GetAttributes
设置文件的属性。Set the attributes of a file. File.SetAttributes
确定文件是否存在。Determine if a file exists. File.Exists
从二进制文件中读取。Read from a binary file. 如何:对新建的数据文件进行读取和写入How to: Read and Write to a Newly Created Data File
写入二进制文件。Write to a binary file. 如何:对新建的数据文件进行读取和写入How to: Read and Write to a Newly Created Data File

适用于

Write(String)

将字符串写入当前字符串。Writes a string to the current string.

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

要写入的字符串。The string to write.

例外

编写器已关闭。The writer is closed.

示例

此代码示例是为类提供的更大示例的一部分 StringWriterThis code example is part of a larger example provided for the StringWriter class.

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

如果指定的字符串为 null ,则不写入任何内容。If the specified string is null, nothing is written.

下表列出了其他典型或相关 i/o 任务的示例。The following table lists examples of other typical or related I/O tasks.

若要执行此操作...To do this... 请参见本主题中的示例...See the example in this topic...
创建文本文件。Create a text file. 如何:将文本写入文件How to: Write Text to a File
写入文本文件。Write to a text file. 如何:将文本写入文件How to: Write Text to a File
读取文本文件。Read from a text file. 如何:从文件中读取文本How to: Read Text from a File
向文件追加文本。Append text to a file. 如何:打开并追加到日志文件How to: Open and Append to a Log File

File.AppendText

FileInfo.AppendText
获取文件的大小。Get the size of a file. FileInfo.Length
获取文件的属性。Get the attributes of a file. File.GetAttributes
设置文件的属性。Set the attributes of a file. File.SetAttributes
确定文件是否存在。Determine if a file exists. File.Exists
从二进制文件中读取。Read from a binary file. 如何:对新建的数据文件进行读取和写入How to: Read and Write to a Newly Created Data File
写入二进制文件。Write to a binary file. 如何:对新建的数据文件进行读取和写入How to: Read and Write to a Newly Created Data File

适用于

Write(StringBuilder)

将字符串生成器的字符串表示形式写入当前字符串。Writes the string representation of a string builder to the current string.

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

要写入字符串的字符串生成器。The string builder to write to the string.

适用于

Write(Char)

将字符写入字符串。Writes a character to the string.

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

要写入的字符。The character to write.

例外

编写器已关闭。The writer is closed.

示例

此代码示例是为构造函数提供的更大示例的一部分 StringWriter()This code example is part of a larger example provided for the StringWriter() constructor.

// 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.WriteThis method overrides TextWriter.Write.

下表列出了其他典型或相关 i/o 任务的示例。The following table lists examples of other typical or related I/O tasks.

若要执行此操作...To do this... 请参见本主题中的示例...See the example in this topic...
创建文本文件。Create a text file. 如何:将文本写入文件How to: Write Text to a File
写入文本文件。Write to a text file. 如何:将文本写入文件How to: Write Text to a File
读取文本文件。Read from a text file. 如何:从文件中读取文本How to: Read Text from a File
向文件追加文本。Append text to a file. 如何:打开并追加到日志文件How to: Open and Append to a Log File

File.AppendText

FileInfo.AppendText
获取文件的大小。Get the size of a file. FileInfo.Length
获取文件的属性。Get the attributes of a file. File.GetAttributes
设置文件的属性。Set the attributes of a file. File.SetAttributes
确定文件是否存在。Determine if a file exists. File.Exists
从二进制文件中读取。Read from a binary file. 如何:对新建的数据文件进行读取和写入How to: Read and Write to a Newly Created Data File
写入二进制文件。Write to a binary file. 如何:对新建的数据文件进行读取和写入How to: Read and Write to a Newly Created Data File

适用于

Write(ReadOnlySpan<Char>)

将字符范围的字符串表示形式写入当前字符串。Writes the string representation of a span of chars to the current string.

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>

要写入字符串中的字符范围。A span of chars to write to the string.

适用于