public static Person[] Extract(String input) { //Mr. John Smith, born on 2001/06/15 List <String> people = MyParser.GetEntries(input, @"(Mr|Mrs)\D+, born on \d{4}/((0\d)|(1[012]))/(([012]\d)|3[01])"); Person[] result = new Person[people.Count]; int i = 0; foreach (String s in people) { Gender Gender = Gender.m; String FirstName; String LastName; DateTime DateOfBirth; String[] parts = s.Split(' '); if (parts[0].Equals("Mrs.")) { Gender = Gender.f; } FirstName = parts[1]; LastName = parts[2].Substring(0, parts[2].Length - 1); DateOfBirth = DateTime.ParseExact(parts[5], "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture); Person res = new Person(Gender, FirstName, LastName, DateOfBirth); result[i++] = res; } return(result); }
public static FootballClub[] Extract(String input) { List <String> clubs = MyParser.GetEntries(input, @"FC\D+\((\D+\d{4})\)"); FootballClub[] result = new FootballClub[clubs.Count]; int i = 0; foreach (String s in clubs) { String name; String country; String city; DateTime established; String[] parts = s.Split(' '); name = parts[1].Substring(0, parts[1].Length); city = parts[2].Substring(1, parts[2].Length - 2); country = parts[3].Substring(0, parts[3].Length - 1); established = DateTime.ParseExact(parts[5].Substring(0, 4), "yyyy", System.Globalization.CultureInfo.InvariantCulture); FootballClub res = new FootballClub(name, country, city, established); result[i++] = res; } return(result); }
public static Company[] Extract(String input) { //Company Microsoft (IT, USA) List <String> companies = MyParser.GetEntries(input, @"Company \D+ \((\D+,\D+)\)"); Company[] result = new Company[companies.Count]; int i = 0; foreach (String s in companies) { String Name; String Segment; String Location; String[] parts = s.Split(' '); Name = parts[1]; Segment = parts[2].Substring(1, parts[2].Length - 2); Location = parts[3].Substring(0, parts[3].Length - 1); Company res = new Company(Name, Segment, Location); result[i++] = res; } return(result); }