fork(16) download
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. String Expression = "2 * 3";
  9. Regex regEx = new Regex(@"([+-]?\d+\.*\d*[eE][+-]?\d+|[-+]?\d+\.*\d*)\s*([/*+-])\s*(-?\d+\.*\d*[eE][+-]?\d+|-?\d+\.*\d*)");
  10.  
  11. Expression = regEx.Replace(Expression,Repl);
  12. Console.WriteLine(Expression);
  13. }
  14.  
  15. public static string Repl(Match m)
  16. {
  17. double result = Convert.ToDouble(m.Groups[3].Value);
  18. result = Convert.ToDouble(m.Groups[3].Value) / 100 * 2;
  19. if (result < 0 || m.Index == 0)
  20. return m.Value.Replace(m.Groups[3].Value, result.ToString());
  21. else
  22. return m.Value.Replace(m.Groups[3].Value, "+" + result.ToString());
  23. }
  24. }
  25.  
  26.  
Success #stdin #stdout 0.13s 24336KB
stdin
Standard input is empty
stdout
2 * 0.06