Advertisement
Mike_Goodman92

Untitled

Nov 4th, 2017
2,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 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. namespace _02.Match_Phone_Number
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. //string phoneString = Console.ReadLine();
  15. //Regex validPhonesPatter = new Regex(@"(\+359([ -])2(\2)(\d{3})(\2)(\d{4}))\b");
  16.  
  17. //MatchCollection phoneCollection = validPhonesPatter.Matches(phoneString);
  18. //List<string> phoneList = new List<string>();
  19.  
  20. //foreach (var phone in phoneCollection)
  21. //{
  22. // phoneList.Add(phone.ToString());
  23. //}
  24.  
  25. //Console.WriteLine(string.Join(", ", phoneList));
  26.  
  27.  
  28.  
  29. // LINQ Решение:
  30.  
  31. string pattern = @"(\+359([ -])2(\2)(\d{3})(\2)(\d{4}))\b";
  32. string phones = Console.ReadLine();
  33.  
  34. MatchCollection phoneMatches = Regex.Matches(phones , pattern);
  35.  
  36. string[] matchPhones = phoneMatches.Cast<Match>().Select(x => x.Value.Trim()).ToArray();
  37. Console.WriteLine(string.Join(", ", matchPhones));
  38.  
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement