I have a text file that looks like this:
Rows ... product.people product.people_good product.people_bad product.boy #product.me ... Rows
I want to put # in front of the product. , and the file should be:
Rows ... #product.people #product.people_good #product.people_bad #product.boy #product.me ... Rows
For this, I use the following code:
string installerfilename = pathTemp + fileArr1; string installertext = File.ReadAllText(installerfilename); var linInst = File.ReadLines(pathTemp + fileArr1).ToArray(); foreach (var txt in linInst) { if (txt.Contains("#product=")) { installertext = installertext.Replace("#product=", "product="); } else if (txt.Contains("product.") && (!txt.StartsWith("#"))) { installertext = installertext.Replace(txt, "#" + txt); } File.WriteAllText(installerfilename, installertext); }
But this code will do the following:
Rows ... #product.people ##product.people_good ##product.people_bad #product.boy #product.me ... Rows
Can anyone explain the way for me? And how can I write only one # in front of these lines?
source share