StringReader(String) コンストラクター
定義
指定した文字列から読み取る StringReader クラスの新しいインスタンスを初期化します。Initializes a new instance of the StringReader class that reads from the specified string.
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 を初期化する目的の文字列。The string to which the StringReader should be initialized.
例外
s
パラメーターが null
です。The s
parameter is null
.
例
このコード例は、StringReader クラスのために提供されている大規模な例の一部です。This code example is part of a larger example provided for the StringReader class.
// From textReaderText, create a continuous paragraph
// with two spaces between each sentence.
String^ aLine;
String^ aParagraph;
StringReader^ strReader = gcnew StringReader( textReaderText );
while ( true )
{
aLine = strReader->ReadLine();
if ( aLine != nullptr )
{
aParagraph = String::Concat( aParagraph, aLine, " " );
}
else
{
aParagraph = String::Concat( aParagraph, "\n" );
break;
}
}
Console::WriteLine( "Modified text:\n\n{0}", aParagraph );
// 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 タスクと関連する 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 |