I am looking to replace several strings and then write them to a .csv file
Everything works fine for me when I replace a single text, but when I want to replace 2 or more, it only takes the last replacement text, which only allows me to put a string after WriteAllText
.
This is my code:
string reemplazo = "";
string reemplazo2 = "";
string Arch = File.ReadAllText(originalFileName); //Aqui leo mi archivo .csv
reemplazo = Regex.Replace(Arch, @"/", @"/");
reemplazo2 = Regex.Replace(Arch, @"–", @"-");
File.WriteAllText(newFileName.Substring(0, newFileName.Length - 4) + "Test.csv", reemplazo); //solo puedo poner un valor del remplazo
File.Move(originalFileName, newFileName);
files.Add(newFileName);
OK.. you have a fairly simple problem, and that is that you are not replacing the text on the string you just used, but always on the original, so the text that remains is only the last replacement.
Actually, replace2 should be:
Replace replaces in a string, and returns a different string with the replacements done. therefore, the next replace must either use that new string.
As a note, you could do replace and send the content to the same string without problems: