ellapt

T14.19.ExtractDisplayDates

Feb 3rd, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Text.RegularExpressions;
  4.  
  5. class ExtractDisplayDates
  6. {
  7. static void Main()
  8. {
  9. Console.WriteLine("Extract all dates of format DD.MM.YYYY. Display in the standard date format for Canada.\n");
  10.  
  11. string text = "Static void Main() 12.10.2012, 25.01.2012";
  12.  
  13. DateTime date;
  14. foreach (Match item in Regex.Matches(text, @"\b\d{2}.\d{2}.\d{4}\b"))
  15. if (DateTime.TryParseExact(item.Value, "dd.MM.yyyy",
  16. CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
  17. {
  18. Console.WriteLine(date.ToString(CultureInfo.GetCultureInfo("en-CA").DateTimeFormat.ShortDatePattern));
  19. }
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment