StringReader(String) Construtor
Definição
Inicializa uma nova instância da classe StringReader que lê da cadeia de caracteres especificada.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)
Parâmetros
- s
- String
A cadeia de caracteres para a qual o StringReader deve ser inicializado.The string to which the StringReader should be initialized.
Exceções
O parâmetro s é null.The s parameter is null.
Exemplos
Este exemplo de código faz parte de um exemplo maior fornecido para a StringReader classe.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)
Comentários
A tabela a seguir lista exemplos de outras tarefas de e/s típicas ou relacionadas.The following table lists examples of other typical or related I/O tasks.
| Para fazer isso...To do this... | Veja o exemplo neste tópico...See the example in this topic... |
|---|---|
| Crie um arquivo de texto.Create a text file. | Como gravar texto em um arquivoHow to: Write Text to a File |
| Gravar em um arquivo de texto.Write to a text file. | Como gravar texto em um arquivoHow to: Write Text to a File |
| Ler de um arquivo de texto.Read from a text file. | Como ler texto de um arquivoHow to: Read Text from a File |
| Acrescentar texto a um arquivo.Append text to a file. | Como abrir e acrescentar a um arquivo de logHow to: Open and Append to a Log File File.AppendText FileInfo.AppendText |
| Obter o tamanho de um arquivo.Get the size of a file. | FileInfo.Length |
| Obter os atributos de um arquivo.Get the attributes of a file. | File.GetAttributes |
| Defina os atributos de um arquivo.Set the attributes of a file. | File.SetAttributes |
| Determine se um arquivo existe.Determine if a file exists. | File.Exists |
| Ler de um arquivo binário.Read from a binary file. | Como ler e gravar em um arquivo de dados recém-criadoHow to: Read and Write to a Newly Created Data File |
| Gravar em um arquivo binário.Write to a binary file. | Como: Ler e gravar em um arquivo de dados recém-criadoHow to: Read and Write to a Newly Created Data File |