/^toto$/
Regex.Replace(text, @"\bVB1\b", "VB2");
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic void ReplaceID(string SearchFor, string ReplaceWith) // OK { // this method use StreamReader, StreamWriter, and Regex to replace a string SearchFor // by a string ReplaceWith //get a StreamReader for reading the file StreamReader reader = new StreamReader(Datapath); //read the entire file at once string contents = reader.ReadToEnd(); //close up and dispose reader.Close(); reader.Dispose(); //use regular expressions to search and replace our text contents = Regex.Replace(contents, SearchFor, ReplaceWith); //get a StreamWriter for writing the new text to the file StreamWriter writer = new StreamWriter(Datapath); //write the contents writer.Write(contents); //close up and dispose writer.Close(); writer.Dispose(); }