I have this function that works great finding and replacing a string in a myText.txt
FileReplaceString("c:\myText.txt", "oldWord", "newWord", false);
public void FileReplaceString(string path, string find, string replace, bool matchcase)
{
TextReader r = new StreamReader(path);
string text = r.ReadToEnd();
r.Close();
text = Regex.Replace(text, Regex.Escape(find), replace, (matchcase) ? RegexOptions.None : RegexOptions.IgnoreCase);
TextWriter w = new StreamWriter(path);
//MessageBox.Show(find);
w.Write(text);
w.Flush();
w.Close();
}
I do not want to replace "oldword" by "newWord". What I need to do is to find the string "oldword" and then read the next 5 character (i.g. the string may look like
xsasdsdadad oldWord12345) and thus reading 12345
Any help is greatly appreciated.