StringReader(String) Konstruktor

Definice

Inicializuje novou instanci StringReader třídy, která čte ze zadaného řetězce.

public:
 StringReader(System::String ^ s);
public StringReader (string s);
new System.IO.StringReader : string -> System.IO.StringReader
Public Sub New (s As String)

Parametry

s
String

Řetězec, do kterého StringReader se má inicializovat.

Výjimky

Parametr s je null.

Příklady

Tento příklad kódu je součástí většího příkladu StringReader pro třídu.

// 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)

Poznámky

Následující tabulka uvádí příklady dalších typických nebo souvisejících vstupně-výstupních úloh.

Požadovaná akce... Další informace naleznete v příkladu v tomto tématu...
Vytvořte textový soubor. Postupy: Zápis textu do souboru
Zápis do textového souboru Postupy: Zápis textu do souboru
Čtení z textového souboru. Postupy: Čtení textu ze souboru
Připojení textu k souboru Postupy: Otevření a připojení k souboru protokolu

File.AppendText

FileInfo.AppendText
Získejte velikost souboru. FileInfo.Length
Získejte atributy souboru. File.GetAttributes
Nastavte atributy souboru. File.SetAttributes
Zjistěte, jestli soubor existuje. File.Exists
Čtení z binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru
Zápis do binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru

Platí pro

Viz také