fork download
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. Console.WriteLine(ReplaceAll("/]a", new[] { '/', ']' }, 'a'));
  11. Console.WriteLine(ReplaceAll("^/]a",new[] { '^', '/', ']' }, '$'));
  12. }
  13. public static string ReplaceAll(string str, char[] charsToReplace, char replacementCharacter)
  14. {
  15. if(string.IsNullOrEmpty(str))
  16. {
  17. return string.Empty;
  18. }
  19.  
  20. var pattern = $"[{string.Concat(charsToReplace).Replace(@"\", @"\\").Replace("-", @"\-").Replace("^", @"\^").Replace("]", @"\]")}]";
  21. return Regex.Replace(str, pattern, replacementCharacter.ToString());
  22. }
  23. }
Success #stdin #stdout 0.06s 21264KB
stdin
Standard input is empty
stdout
aaa
$$$a