コード例 #1
0
        public static Plant[] Extract(String input)
        {
            var           type   = typeof(Plant);
            RegexStr      reg    = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> plants = MyParser.GetEntries(input, reg.Value);

            Plant[] result = new Plant[plants.Count];
            int     i      = 0;

            foreach (String s in plants)
            {
                String   Name;
                String   Type;
                String   Location;
                int      height;
                String[] parts = s.Split(' ');
                Name     = parts[1];
                Type     = parts[2].Substring(1, parts[2].Length - 2);
                Location = parts[3].Substring(0, parts[3].Length - 1);
                height   = Int32.Parse(parts[4].Substring(0, parts[4].Length - 1));


                Plant res = new Plant(Name, Type, height, Location);
                result[i++] = res;
            }
            return(result);
        }
コード例 #2
0
        public static Person[] Extract(String input)
        {
            var           type   = typeof(Person);
            RegexStr      reg    = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> people = MyParser.GetEntries(input, reg.Value);

            //Mr. John Smith was born on 2001/06/15
            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];
                DateOfBirth = DateTime.ParseExact(parts[6], "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture);
                Person res = new Person(Gender, FirstName, LastName, DateOfBirth);
                result[i++] = res;
            }
            return(result);
        }
コード例 #3
0
        public static FootballClub[] Extract(String input)
        {
            var      type = typeof(FootballClub);
            RegexStr reg  = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));

            List <String> clubs = MyParser.GetEntries(input, reg.Value);

            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);
        }
コード例 #4
0
        public static Newspaper[] Extract(String input)
        {
            var           type       = typeof(Newspaper);
            RegexStr      reg        = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> newspapers = MyParser.GetEntries(input, reg.Value);

            Newspaper[] result = new Newspaper[newspapers.Count];
            int         i      = 0;

            foreach (String s in newspapers)
            {
                String   Name;
                String   Country;
                String   Frequency;
                String   Subject;
                String[] parts = s.Split(' ');
                Name      = parts[1].Substring(0, parts[1].Length - 1);
                Country   = parts[2];
                Frequency = parts[3].Substring(1, parts[3].Length - 2);
                Subject   = parts[4].Substring(0, parts[4].Length - 1);
                Newspaper res = new Newspaper(Name, Country, Frequency, Subject);
                result[i++] = res;
            }
            return(result);
        }
コード例 #5
0
        public static Car[] Extract(String input)
        {
            var           type = typeof(Car);
            RegexStr      reg  = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> cars = MyParser.GetEntries(input, reg.Value);

            Car[] result = new Car[cars.Count];
            int   i      = 0;

            foreach (String s in cars)
            {
                String   Model;
                String   Manufacturer;
                String   Transmission;
                String   Owner;
                String[] parts = s.Split(' ');
                Manufacturer = parts[1];
                Model        = parts[2];
                Transmission = parts[3].Substring(1, parts[3].Length - 2);
                Owner        = parts[4].Substring(0, parts[4].Length - 1);


                Car res = new Car(Model, Manufacturer, Transmission, Owner);
                result[i++] = res;
            }
            return(result);
        }
コード例 #6
0
        public static Animal[] Extract(String input)
        {
            var           type    = typeof(Animal);
            RegexStr      reg     = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> animals = MyParser.GetEntries(input, reg.Value);

            //Animal Zebra (equids, Africa)
            Animal[] result = new Animal[animals.Count];
            int      i      = 0;

            foreach (String s in animals)
            {
                String   Name;
                String   Species;
                String   Location;
                String[] parts = s.Split(' ');
                Name     = parts[1];
                Species  = parts[2].Substring(1, parts[2].Length - 2);
                Location = parts[3].Substring(0, parts[3].Length - 1);
                Animal res = new Animal(Name, Species, Location);
                result[i++] = res;
            }
            return(result);
        }
コード例 #7
0
        public static Company[] Extract(String input)
        {
            var           type      = typeof(Company);
            RegexStr      reg       = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> companies = MyParser.GetEntries(input, reg.Value);

            //Company Microsoft (IT, USA)
            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);
        }
コード例 #8
0
        public static Bicycle[] Extract(String input)
        {
            var           type     = typeof(Bicycle);
            RegexStr      reg      = (RegexStr)type.GetTypeInfo().GetCustomAttribute(typeof(RegexStr));
            List <String> bicycles = MyParser.GetEntries(input, reg.Value);

            Bicycle[] result = new Bicycle[bicycles.Count];
            int       i      = 0;

            foreach (String s in bicycles)
            {
                String   Model;
                String   Manufacturer;
                String   Owner;
                String[] parts = s.Split(' ');
                Manufacturer = parts[1];
                Model        = parts[2];
                Owner        = parts[3].Substring(1, parts[3].Length - 2);

                Bicycle res = new Bicycle(Model, Manufacturer, Owner);
                result[i++] = res;
            }
            return(result);
        }