string path = @"c:\Montexte.txt"; using(StreamReader reader = new StreamReader(path)) { while (reader.Peek() >= 0) { string maligne = reader.ReadLine(); if (maligne.StartsWith(nombretrouve.ToString() + " ")) { ligne.Text = "blabla"; } } }
string path = @"c:\Montexte.txt"; StreamReader reader = new StreamReader(path); string maligne; do // début de boucle { maligne = reader.ReadLine(); if (maligne != null) // S'il y a une nouvelle ligne (qu'on est pas à la fin du fichier) { if (maligne.StartsWith(nombretrouve.ToString())) { ligne.Text = maligne.Replace(nombretrouve.ToString() + " ", ""); break; // Si on a trouvé la ligne, on sort de la boucle } } } while(maligne != null); // On recommence la boucle tant qu'il reste des lignes
string path = @"c:\Montexte.txt"; StreamReader reader = new StreamReader(path); for (int i = 0; i < 20; i++) { string maligne = reader.ReadLine(); if (maligne.StartsWith(nombretrouve.ToString() + " ")) { ligne.Text = "blabla"; } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionstring path = @"c:\Montexte.txt"; StreamReader reader = new StreamReader(path); for (int i = 0; i < 9; i++) { string maligne = reader.ReadLine(); if (maligne.StartsWith(nombretrouve.ToString())) { ligne.Text = maligne.Replace(nombretrouve.ToString() + " ", ""); } }