0

Given a sample string as follows in the equation variable, I have to remove the commas and spaces, and replace × with * and ÷ with /. Is it possible to have one line of Regex.Replace and combine these four patterns into one expression/line?

    string equation = "1,250 ×3.5÷   12";
    equationModified = Regex.Replace(equation, @",", "");
    equationModified = Regex.Replace(equationModified, @" ", "");
    equationModified = Regex.Replace(equationModified, @"×", "*");
    equationModified = Regex.Replace(equationModified, @"÷", "/");

Expected output: "1250*3.5/12"

EsAMe
  • 305
  • 2
  • 13
  • anyone know which method would be faster in terms of performance. my original method or the Dictionary method in the other thread. – EsAMe Sep 29 '19 at 07:47
  • I would advise to only use regex for more complex patterns, or when you want the pattern to be configurable. In this case - and especially with performance in mind - I'd stay away from regex. – C.Evenhuis Sep 29 '19 at 08:33

0 Answers0