Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _19.EtractDates
- {
- /*Write a program that extracts from a given text all dates that match the format DD.MM.YYYY.
- * Display them in the standard date format for Canada.*/
- class Program
- {
- static void Main(string[] args)
- {
- string text = "I was born at 14.06.1980. My sister was born at 3.7.1984. In 5/1999 I graduated my high school. The law says (see section 7.3.12) that we are allowed to do this (section 7.4.2.9).";
- foreach (var extracted in Regex.Matches(text, @"((((0?[1-9])|[12][0-9]|3[01])\.((0?[13578])|(1[02])))|(((0?[1-9])|[12][0-9]|30)\.((0?[469])|11))|(((0?[1-9])|[12][0-9])\.(0?2)))\.\d{4}"))
- {
- string extractedToString = Convert.ToString(extracted);
- DateTime date = DateTime.ParseExact(extractedToString, "dd.MM.yyyy", CultureInfo.InvariantCulture);
- Console.WriteLine(date.ToString(CultureInfo.GetCultureInfo("en-CA")));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement