StringReader(String) コンストラクター

定義

指定した文字列から読み取る 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;
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 タスクの例を示します。

目的 参照項目
テキスト ファイルを作成します。 方法: テキストのファイルへの書き込み
テキスト ファイルに書き込みます。 方法: テキストのファイルへの書き込み
テキスト ファイルから読み取ります。 方法: ファイルからのテキストの読み取り
ファイルにテキストを追加します。 方法: ログ ファイルを開いて情報を追加する

File.AppendText

FileInfo.AppendText
ファイルのサイズを取得します。 FileInfo.Length
ファイルの属性を取得します。 File.GetAttributes
ファイルの属性を設定します。 File.SetAttributes
ファイルが存在するかどうかを確認します。 File.Exists
バイナリ ファイルから読み取ります。 方法: 新しく作成されたデータ ファイルに対して読み書きする
バイナリ ファイルに書き込みます。 方法: 新しく作成されたデータ ファイルに対して読み書きする

適用対象

こちらもご覧ください