Share via


StringReader(String) Constructeur

Définition

Initialise une nouvelle instance de la classe StringReader qui lit la chaîne spécifiée.

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

Paramètres

s
String

Chaîne à laquelle StringReader doit être initialisé.

Exceptions

Le paramètre s a la valeur null.

Exemples

Cet exemple de code fait partie d’un exemple plus grand fourni pour la StringReader classe .

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

Remarques

Le tableau suivant répertorie des exemples d’autres tâches d’E/S classiques ou connexes.

Action à réaliser... Consultez l'exemple décrit dans cette rubrique...
Créer un fichier texte. Procédure : écrire du texte dans un fichier
Écrire dans un fichier texte. Procédure : écrire du texte dans un fichier
Lire à partir d’un fichier texte. Procédure : lire le texte d’un fichier
Ajoutez du texte à un fichier. Procédure : ouvrir un fichier journal et y ajouter des éléments

File.AppendText

FileInfo.AppendText
Obtenir la taille d’un fichier. FileInfo.Length
Obtenir les attributs d’un fichier. File.GetAttributes
Définissez les attributs d’un fichier. File.SetAttributes
Déterminez si un fichier existe. File.Exists
Lire à partir d’un fichier binaire. Procédure : lire et écrire dans un fichier de données créé récemment
Écrire dans un fichier binaire. Procédure : lire et écrire dans un fichier de données créé récemment

S’applique à

Voir aussi