fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Globalization;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var strings = new List<string> { "Van Den Broek", "Derksen-van 't schip", "In Het Lid-Van De Boer"};
  12. var textInfo = new CultureInfo("en-US", false).TextInfo;
  13. var pattern = new Regex(@"\b(Van|Den|Der|In|de|het)\b(?:\s+(\w+))?", RegexOptions.Compiled|RegexOptions.IgnoreCase);
  14. foreach (var s in strings)
  15. Console.WriteLine(pattern.Replace(s, m => textInfo.ToTitleCase(m.Groups[1].Value) +
  16. (m.Groups[2].Success ? $" {m.Groups[2].Value.ToLower()}" : "")));
  17. }
  18. }
Success #stdin #stdout 0.08s 30388KB
stdin
Standard input is empty
stdout
Van den Broek
Derksen-Van 't schip
In het Lid-Van de Boer