StringWriter.Write 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將資料寫入字串。
多載
| 名稱 | Description |
|---|---|
| Write(Char[], Int32, Int32) |
將一個字元子陣列寫入字串。 |
| Write(String) |
將字串寫入目前的字串。 |
| Write(StringBuilder) |
將字串建構器的字串表示寫入目前字串。 |
| Write(Char) |
寫入字元到字串。 |
| Write(ReadOnlySpan<Char>) |
將一組字元的字串表示寫入當前字串。 |
Write(Char[], Int32, Int32)
將一個字元子陣列寫入字串。
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 寫入資料字元,StringWriterbuffer從位置 index開始。
下表列出其他典型或相關的 I/O 任務範例。
| 若要這麼做... | 請參閱本主題中的範例... |
|---|---|
| 建立文字檔。 | 如何:將文字寫入檔案 |
| 寫入文字檔。 | 如何:將文字寫入檔案 |
| 從文字檔讀取。 | 如何:從檔案讀取文字 |
| 在檔案中附加文字。 |
如何:開啟並附加至記錄檔 File.AppendText FileInfo.AppendText |
| 拿出檔案大小。 | FileInfo.Length |
| 取得檔案的屬性。 | File.GetAttributes |
| 設定檔案的屬性。 | File.SetAttributes |
| 判斷是否有檔案存在。 | File.Exists |
| 從二進位檔案讀取。 | 如何:讀取和寫入新建立的數據檔 |
| 寫入二進位檔案。 | 如何:讀取和寫入新建立的數據檔 |
另請參閱
適用於
Write(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
要寫入的字串。
例外狀況
作者已關閉。
範例
此程式碼範例是本類別更大範例 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)
將字串建構器的字串表示寫入目前字串。
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)
寫入字元到字串。
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>)
將一組字元的字串表示寫入當前字串。
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>
用一串字元寫入字串。