Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Globalization;
- namespace _19.ExtractDates
- {
- class ExtractDates
- {
- /* 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 void Main()
- {
- StreamReader textReader = new StreamReader(@"..\..\Dates.txt");
- string[] textSplit;
- using (textReader)
- {
- string text = textReader.ReadToEnd();
- textSplit = text.Split(' ', '\r', '\t', '\n');// why not-->, StringSplitOptions.RemoveEmptyEntries);
- }
- List<string> wordsWithNumbers = new List<string>();
- for (int i = 0; i < textSplit.Length; i++)
- {
- if (textSplit[i].Length > 0 && (textSplit[i][0] - '0' >= 0 && textSplit[i][0] - '0' <= 9))
- {
- if ((textSplit[i][textSplit[i].Length - 1] == '.' || textSplit[i][textSplit[i].Length - 1] == ',' || textSplit[i][textSplit[i].Length - 1] == ')'
- || textSplit[i][textSplit[i].Length - 1] == ';'))
- {
- textSplit[i] = textSplit[i].Remove(textSplit[i].Length - 1);
- }
- wordsWithNumbers.Add(textSplit[i]);
- }
- }
- Console.WriteLine("all words starting with digits");
- for (int i = 0; i < wordsWithNumbers.Count; i++)
- {
- Console.WriteLine(wordsWithNumbers[i]);
- }
- Console.WriteLine();
- Console.WriteLine("all datas");
- for (int i = 0; i < wordsWithNumbers.Count; i++)
- {
- DateTime data;
- if (DateTime.TryParse(wordsWithNumbers[i], out data ))
- {
- Console.WriteLine(wordsWithNumbers[i]);
- }
- }
- }
- }
- }
- /*here is the text
- * AN EXAMPLE OF A SHORT AUTOBIOGRAPHY
- I was born in a warm, sunny day on 12.08.1976 in Florida , USA. I still live in Florida , USA ,
- and I go to school at Booker High School. I live with my mom, Kate; my brother, Jake; and my Aunt Molly. When I was born,
- my bother was 5-months-old (that means he was bor in 1976) and hid under the table from me. Jake is a sweet kid and he would do anything for me,
- but like all brothers and sisters we fight like cats and dogs. Sometimes when no one was around, Jake would come up to
- me and bite my toes for no reason. I still love him but only because he is my brother.
- My name is Sally Friday. I started school on 1.9.82 when I was six-years-old. I went to kindergarten through
- fifth grade at Booker Elementary and while I was there, I won an award for perfect attendance on 1983.5.4. I also won
- an award for honor roll all 4 terms but 1st one was on 9.03.84. Then I attended Booker Middle School on 25.9.84,
- and there I also won a couple of awards: 1 for perfect attendance and 2nd for being named Student of the Year--
- one in 6th grade and the other in 8th grade. I am now a senior at Booker High School. I plan on finishing
- school and maybe going to a community college in 93.
- Life to me means friends and family who you can trust and who trusts you. I am pretty much on the happy
- side of life, but like all teens I do I have my "days of." That means I do have some sad days or
- depressed days like 26/10/2010. I have a few frinds here that sort of look out for me and when I am having a bad day - another one 2011.11.31,
- I have someone here at school to talk to. I make my school days go by thinking of either the next hour
- or what I will do when I get home or on the weekend. I'm not seeing anyone now but when I did have a
- boyfriend, our favorite places to go were the movies and out to dinner. Sometimes we went to the beach.
- Only once we went to an amusement park: Universal Studios. We were together for twenty-nine days and
- then we broke-up; so no, I don't think it was forever.
- The year 2018 will make twenty years since I graduated from high school. I think I will probably
- be still living here in Sarasota (sinse my birth in 76). I will be quite comfortable with my living situation, meaning
- that I will be married to Paul Smith. We will have 1 child: Linda Treasa Smith, who at that point
- will be 3-years-old and a little devil. Paul is a sweet guy; he will do anything for anyone. He is
- 6 feet tall and built well. He has baby blue eyes and blond hair. We will have been together
- for 5 years and will be happy together--this is forever.
- As I said in the beginning, I was born here in Florida and I've lived here my whole life.
- I would like to see more of the USA but unfortunatly, I don't have any money to leave
- Florida to go anywhere right now. I hope you have enjoyed reading my life story as much as
- I have enjoyed writing it for you. Try to get as much as you can out of school; you're only
- there for 12 years and when you graduate, you're home free. Here's a tip for you to live
- or try to live by: If you think it, it can be done.
- Written by Erika Baker
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement