StringReader(String) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化一個新的類別實例 StringReader ,讀取指定的字串。
public:
StringReader(System::String ^ s);
public StringReader(string s);
new System.IO.StringReader : string -> System.IO.StringReader
Public Sub New (s As String)
參數
- s
- String
應該初始化的 StringReader 字串。
例外狀況
參數 s 為 null。
範例
此程式碼範例是本類別更大範例 StringReader 的一部分。
// From textReaderText, create a continuous paragraph
// with two spaces between each sentence.
string aLine, aParagraph = null;
StringReader strReader = new StringReader(textReaderText);
while(true)
{
aLine = strReader.ReadLine();
if(aLine != null)
{
aParagraph = aParagraph + aLine + " ";
}
else
{
aParagraph = aParagraph + "\n";
break;
}
}
Console.WriteLine("Modified text:\n\n{0}", aParagraph);
' From textReaderText, create a continuous paragraph
' with two spaces between each sentence.
Dim aLine, aParagraph As String
Dim strReader As New StringReader(textReaderText)
While True
aLine = strReader.ReadLine()
If aLine Is Nothing Then
aParagraph = aParagraph & vbCrLf
Exit While
Else
aParagraph = aParagraph & aLine & " "
End If
End While
Console.WriteLine("Modified text:" & vbCrLf & vbCrLf & _
aParagraph)
備註
下表列出其他典型或相關的 I/O 任務範例。
| 若要這麼做... | 請參閱本主題中的範例... |
|---|---|
| 建立文字檔。 | 如何:將文字寫入檔案 |
| 寫入文字檔。 | 如何:將文字寫入檔案 |
| 從文字檔讀取。 | 如何:從檔案讀取文字 |
| 在檔案中附加文字。 |
如何:開啟並附加至記錄檔 File.AppendText FileInfo.AppendText |
| 拿出檔案大小。 | FileInfo.Length |
| 取得檔案的屬性。 | File.GetAttributes |
| 設定檔案的屬性。 | File.SetAttributes |
| 判斷是否有檔案存在。 | File.Exists |
| 從二進位檔案讀取。 | 如何:讀取和寫入新建立的數據檔 |
| 寫入二進位檔案。 | 如何:讀取和寫入新建立的數據檔 |