StringWriter.Write 方法

定義

將資料寫入字串。

多載

Write(Char[], Int32, Int32)

將字元子陣列寫入此字串。

Write(String)

將字串寫入目前的字串。

Write(StringBuilder)

將字串產生器的字串表示寫入目前字串。

Write(Char)

將一個字元寫入字串。

Write(ReadOnlySpan<Char>)

將字元範圍的字串表示寫入目前字串。

Write(Char[], Int32, Int32)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
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

這個方法會count從 位置開始index,將資料buffer字元寫入這個 StringWriter

下表列出其他一般或相關 I/O 工作的範例。

作法... 請參閱這個主題中的範例…
建立文字檔 作法:將文字寫入檔案
寫入文字檔。 作法:將文字寫入檔案
從文字檔讀取。 作法:讀取檔案中的文字
將文字附加至檔案。 作法:開啟並附加至記錄檔

File.AppendText

FileInfo.AppendText
取得檔案的大小。 FileInfo.Length
取得檔案的屬性。 File.GetAttributes
設定檔案的屬性。 File.SetAttributes
判斷檔案是否存在。 File.Exists
從二進位檔讀取。 作法:讀取和寫入新建立的資料檔案
寫入二進位檔。 作法:讀取和寫入新建立的資料檔案

另請參閱

適用於

Write(String)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
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)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
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)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
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>)

來源:
StringWriter.cs
來源:
StringWriter.cs
來源:
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>

要寫入字串的字元範圍。

適用於