StringReader(String) Konstruktor

Definicja

Inicjuje StringReader nowe wystąpienie klasy, która odczytuje z określonego ciągu.

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

Ciąg, do którego StringReader ma zostać zainicjowany.

Wyjątki

Parametr s ma wartość null.

Przykłady

Ten przykład kodu jest częścią większego przykładu udostępnionego StringReader dla klasy .

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

Uwagi

W poniższej tabeli wymieniono przykłady innych typowych lub powiązanych zadań we/wy.

Aby wykonać tę czynność... Zobacz przykład w tym temacie...
Twórca pliku tekstowego. Instrukcje: Zapisywanie tekstu w pliku
Zapisywanie w pliku tekstowym. Instrukcje: Zapisywanie tekstu w pliku
Odczyt z pliku tekstowego. Instrukcje: Odczytywanie tekstu z pliku
Dołączanie tekstu do pliku. Instrukcje: Otwieranie pliku dziennika i dołączanie do niego

File.AppendText

FileInfo.AppendText
Pobierz rozmiar pliku. FileInfo.Length
Pobierz atrybuty pliku. File.GetAttributes
Ustaw atrybuty pliku. File.SetAttributes
Ustal, czy plik istnieje. File.Exists
Odczyt z pliku binarnego. Instrukcje: Odczyt i zapis we właśnie utworzonym pliku danych
Zapisywanie w pliku binarnym. Instrukcje: Odczyt i zapis we właśnie utworzonym pliku danych

Dotyczy

Zobacz też