Advertisement
geniusvil

String&Text - 19

Jan 3rd, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Globalization;
  8.  
  9. namespace _19.ExtractDates
  10. {
  11. class ExtractDates
  12. {
  13. /* Write a program that extracts from a given
  14. * text all dates that match the format DD.MM.YYYY.
  15. * Display them in the standard date format for Canada.
  16. */
  17.  
  18. static void Main()
  19. {
  20. StreamReader textReader = new StreamReader(@"..\..\Dates.txt");
  21. string[] textSplit;
  22. using (textReader)
  23. {
  24. string text = textReader.ReadToEnd();
  25. textSplit = text.Split(' ', '\r', '\t', '\n');// why not-->, StringSplitOptions.RemoveEmptyEntries);
  26. }
  27.  
  28. List<string> wordsWithNumbers = new List<string>();
  29.  
  30. for (int i = 0; i < textSplit.Length; i++)
  31. {
  32. if (textSplit[i].Length > 0 && (textSplit[i][0] - '0' >= 0 && textSplit[i][0] - '0' <= 9))
  33. {
  34. if ((textSplit[i][textSplit[i].Length - 1] == '.' || textSplit[i][textSplit[i].Length - 1] == ',' || textSplit[i][textSplit[i].Length - 1] == ')'
  35. || textSplit[i][textSplit[i].Length - 1] == ';'))
  36. {
  37. textSplit[i] = textSplit[i].Remove(textSplit[i].Length - 1);
  38. }
  39. wordsWithNumbers.Add(textSplit[i]);
  40. }
  41. }
  42. Console.WriteLine("all words starting with digits");
  43. for (int i = 0; i < wordsWithNumbers.Count; i++)
  44. {
  45. Console.WriteLine(wordsWithNumbers[i]);
  46. }
  47. Console.WriteLine();
  48. Console.WriteLine("all datas");
  49. for (int i = 0; i < wordsWithNumbers.Count; i++)
  50. {
  51. DateTime data;
  52. if (DateTime.TryParse(wordsWithNumbers[i], out data ))
  53. {
  54. Console.WriteLine(wordsWithNumbers[i]);
  55. }
  56. }
  57. }
  58. }
  59. }
  60. /*here is the text
  61. * AN EXAMPLE OF A SHORT AUTOBIOGRAPHY
  62. I was born in a warm, sunny day on 12.08.1976 in Florida , USA. I still live in Florida , USA ,
  63. 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,
  64. 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,
  65. but like all brothers and sisters we fight like cats and dogs. Sometimes when no one was around, Jake would come up to
  66. me and bite my toes for no reason. I still love him but only because he is my brother.
  67.  
  68. My name is Sally Friday. I started school on 1.9.82 when I was six-years-old. I went to kindergarten through
  69. fifth grade at Booker Elementary and while I was there, I won an award for perfect attendance on 1983.5.4. I also won
  70. 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,
  71. and there I also won a couple of awards: 1 for perfect attendance and 2nd for being named Student of the Year--
  72. one in 6th grade and the other in 8th grade. I am now a senior at Booker High School. I plan on finishing
  73. school and maybe going to a community college in 93.
  74.  
  75. Life to me means friends and family who you can trust and who trusts you. I am pretty much on the happy
  76. side of life, but like all teens I do I have my "days of." That means I do have some sad days or
  77. 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,
  78. I have someone here at school to talk to. I make my school days go by thinking of either the next hour
  79. 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
  80. boyfriend, our favorite places to go were the movies and out to dinner. Sometimes we went to the beach.
  81. Only once we went to an amusement park: Universal Studios. We were together for twenty-nine days and
  82. then we broke-up; so no, I don't think it was forever.
  83.  
  84. The year 2018 will make twenty years since I graduated from high school. I think I will probably
  85. be still living here in Sarasota (sinse my birth in 76). I will be quite comfortable with my living situation, meaning
  86. that I will be married to Paul Smith. We will have 1 child: Linda Treasa Smith, who at that point
  87. will be 3-years-old and a little devil. Paul is a sweet guy; he will do anything for anyone. He is
  88. 6 feet tall and built well. He has baby blue eyes and blond hair. We will have been together
  89. for 5 years and will be happy together--this is forever.
  90.  
  91. As I said in the beginning, I was born here in Florida and I've lived here my whole life.
  92. I would like to see more of the USA but unfortunatly, I don't have any money to leave
  93. Florida to go anywhere right now. I hope you have enjoyed reading my life story as much as
  94. I have enjoyed writing it for you. Try to get as much as you can out of school; you're only
  95. there for 12 years and when you graduate, you're home free. Here's a tip for you to live
  96. or try to live by: If you think it, it can be done.
  97.  
  98. Written by Erika Baker
  99. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement