Advertisement
Terziyski

Match Full Name

Jul 4th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 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 _1.Match_Full_Name
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string regex = @"(\b[A-Z][a-z]{1,}\b {1}\b[A-Z][a-z]+\b)";
  15.             string names = Console.ReadLine();
  16.  
  17.             MatchCollection matchedNames = Regex.Matches(names, regex);
  18.  
  19.             var result = new List<string>();
  20.  
  21.             foreach (Match name in matchedNames)
  22.             {
  23.                 result.Add(name.Value);
  24.             }
  25.  
  26.             foreach (var item in result.Distinct())
  27.             {
  28.                 Console.Write(item + " ");
  29.             }
  30.             Console.WriteLine();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement