I want to add a specific String into an existing String whenever the existing String contains one of the following characters: =, +, -, * or /.
For example, I want to add the String "test" into this existing String:
"=ABC+DEF"
Resulting String should be: "=testABC+testDEF"
My first version looks like this and I quess it works but code is ugly
string originalFormula;
string newFormula1 = originalFormula.Replace("=", "=test");
string newFormula2 = newFormula1.Replace("+", "+test");
string newFormula3 = newFormula2 .Replace("-", "-test");
string newFormula4 = newFormula3 .Replace("*", "*test");
string newFormula5 = newFormula4 .Replace("/", "/test");
Is there some shorter way to achive it ?
Replacereturns the updated string, you could just chain eachReplacecall:string newFormula = originalFormula.Replace("=", "=test").Replace("+", "+test").Replace("-", "-test").Replace("*", "*test").Replace("/", "/test");- I don't know if it makes it more readable though."[=+*/-]", the replacement is"$$test"... See regexstorm.net/tester?p=%5b%3d%2b*%2f-%5d&i=%3dABC%2bDEF&r=%24%24test .