Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted

1 solution

C#
text.Substring(text.IndexOf("text") + 4, 5);

does that help any?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900