Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- class ExtractDatesFromTextPrintThemInCanadnFormat
- {
- //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.
- static DateTime ParseDate(string dateAsString)
- {
- DateTime date = DateTime.ParseExact(dateAsString, "dd.MM.yyyy", CultureInfo.InvariantCulture);
- return date;
- }
- static void Main()
- {
- string text = "ПРЕДСТОЯЩИ ДАТИ CAE - 2 /09.02.2013/ CAE - 1 16.02.2013 TKT Module 1 - 2 23.02.2013. CAE На компютър София 16.02.2013 от: 09/02 до: 16/02 01.02.2013 318.00 лв. FCE На компютър София 23.02.2013 от: 16/02 до: 23/02 08.02.2013 305.00 лв. Регистрирай се";
- List <DateTime> datesList = new List<DateTime>();
- foreach (Match item in Regex.Matches(text, @"\b[0-9]{2}.[0-9]{2}.[0-9]{4}\b"))
- {
- DateTime date = ParseDate(item.Value);
- datesList.Add(date);
- }
- foreach (DateTime date in datesList)
- {
- Console.WriteLine(date.ToString(CultureInfo.GetCultureInfo("en-CA").DateTimeFormat.ShortDatePattern));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement