Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace RegexTest
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string Test1 = "Kov ács Lá szl ó";
  13.             string Test2 = "Ád ámk a Ö dö n";
  14.             string Test3 = "Sc hä ffer Brü n hil da Kl ár a";
  15.             Console.WriteLine("Regex:");
  16.             Console.WriteLine("{0} -> {1}", Test1, GetName(Test1));
  17.             Console.WriteLine("{0} -> {1}", Test2, GetName(Test2));
  18.             Console.WriteLine("{0} -> {1}", Test3, GetName(Test3));
  19.             Console.ReadLine();
  20.         }
  21.  
  22.         private static string GetName(string text)
  23.         {
  24.             string s = "";
  25.             string rxNevCI = @"([\p{Lu}\p{Lt}\p{Lo}\p{Lm}][\p{Ll}\p{Lo}\p{Lm}\s']*[\p{Ll}\p{Lo}\p{Lm}'])";
  26.             Regex rx = new Regex(rxNevCI, RegexOptions.CultureInvariant);
  27.             MatchCollection mc = rx.Matches(text);
  28.             foreach(Match m in mc)
  29.                 s += m.Value.Replace(" ", "") + " ";
  30.             s = s.Trim();
  31.             return s;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement