adsense

Monday, February 2, 2015

Find and replace text in a file in c#

The easiest way to find and replace text in a file is to use the Replace method of string as shown below.

string content= File.ReadAllText("FileName.txt");
text =
content.Replace("find text", "replace text");
File.WriteAllText("
FileName.txt", text);

You can use the Regex.Replace method for more complex replacements

Cheers,
Samitha 

No comments:

Post a Comment