petarkobakov

Fancy Barcodes

Jul 31st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace Fancy_Barcodes
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int barcodesCount = int.Parse(Console.ReadLine());
  12.  
  13. string pattern = @"^@#+(?<product>(?=[A-Z])([A-Za-z0-9]{6,})(?<=[A-Z]))@#+$";
  14.  
  15. for (int i = 1; i <= barcodesCount; i++)
  16. {
  17. string currentCode = Console.ReadLine();
  18. string code = string.Empty;
  19. Match codeValidation = Regex.Match(currentCode, pattern);
  20.  
  21. if (codeValidation.Success)
  22. {
  23. string productName = codeValidation.Groups["product"].Value;
  24.  
  25.  
  26. for (int k = 0; k < productName.Length; k++)
  27. {
  28. if (Char.IsDigit(productName[k]))
  29. {
  30. code += productName[k];
  31.  
  32. }
  33. }
  34. if (code==string.Empty)
  35. {
  36. code = "00";
  37. }
  38. Console.WriteLine($"Product group: {code}");
  39. }
  40.  
  41. else
  42. {
  43. Console.WriteLine("Invalid barcode");
  44. }
  45. }
  46.  
  47. }
  48. }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment