Advertisement
bsbo

Untitled

May 28th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. class PhoneNumbers
  10. {
  11. static void Main()
  12. {
  13. StringBuilder textInput = new StringBuilder();
  14.  
  15. while (true)
  16. {
  17. string lineInput = Console.ReadLine();
  18. if (lineInput=="END")
  19. {
  20. break;
  21. }
  22. else
  23. {
  24. textInput.Append(lineInput);
  25. }
  26. }
  27. string text = textInput.ToString();
  28. string pattern = @"([A-Z][a-zA-Z]*)[^a-zA-Z\+]+?(?=\+|[0-9]{2})([0-9\+]{0,1}[0-9][0-9\/(). -]*[0-9])";
  29. MatchCollection matches = Regex.Matches(text, pattern);
  30.  
  31. if (matches.Count==0)
  32. {
  33. Console.WriteLine("<p>No matches!</p>");
  34. }
  35. else
  36. {
  37.  
  38. Console.Write("<ol>");
  39. for (int i = 0; i < matches.Count; i++)
  40. {
  41. string name = matches[i].Groups[1].ToString();
  42. string phoneNumber = matches[i].Groups[2].ToString();
  43. phoneNumber = phoneNumber.Replace("(", ""); // “(“, “)”, “/”, “.”, “-”, “ “
  44. phoneNumber = phoneNumber.Replace(")", "");
  45. phoneNumber = phoneNumber.Replace("/", "");
  46. phoneNumber = phoneNumber.Replace(".", "");
  47. phoneNumber = phoneNumber.Replace("-", "");
  48. phoneNumber = phoneNumber.Replace(" ", "");
  49.  
  50. string result = "<li><b>" + name + ":</b> " + phoneNumber + "</li>";
  51. Console.Write(result);
  52. }
  53. Console.WriteLine("</ol>");
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement