StringReader(String) Constructeur
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la StringReader classe qui lit à partir de 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 l’initialisation StringReader doit être initialisée.
Exceptions
Le s paramètre est 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, 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.
| Pour ce faire... | Consultez l’exemple de cette rubrique... |
|---|---|
| Créez un fichier texte. | Guide pratique pour écrire du texte dans un fichier |
| Écrire dans un fichier texte. | Guide pratique pour écrire du texte dans un fichier |
| Lire à partir d’un fichier texte. | Guide pratique pour lire du texte à partir d’un fichier |
| Ajoutez du texte à un fichier. |
Guide pratique pour ouvrir et ajouter à un fichier journal File.AppendText FileInfo.AppendText |
| Obtenez 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. | Guide pratique pour lire et écrire dans un fichier de données nouvellement créé |
| Écrivez dans un fichier binaire. | Guide pratique pour lire et écrire dans un fichier de données nouvellement créé |