fork download
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. private static string[] productCodes = new[] {
  9. "MD0133776311I",
  10. "M10133776311I",
  11. "M20133776311I"
  12. };
  13.  
  14. private static Dictionary<char, char> replacementMap = new Dictionary<char, char> {
  15. { '1', 'I' },
  16. { '2', 'S' },
  17. };
  18.  
  19. private static Regex startsWithTwoLettersRegex = new Regex("^([A-Z]{2})");
  20.  
  21. public static void Main()
  22. {
  23. foreach (var code in productCodes)
  24. {
  25. Console.Write("{0} -> ", code);
  26. if (!startsWithTwoLettersRegex.Match(code).Success)
  27. {
  28. Console.WriteLine(FixProductCode(code));
  29. }
  30. else
  31. {
  32. Console.WriteLine("OK!");
  33. }
  34. }
  35. }
  36.  
  37. static string FixProductCode(string code)
  38. {
  39. StringBuilder sb = new StringBuilder(code);
  40. sb[1] = replacementMap[code[1]];
  41. return sb.ToString();
  42. }
  43. }
Success #stdin #stdout 0.08s 34888KB
stdin
Standard input is empty
stdout
MD0133776311I -> OK!
M10133776311I -> MI0133776311I
M20133776311I -> MS0133776311I