Regex to Get Date and Numbers

inkedGFX

Well-known member
Joined
Feb 2, 2013
Messages
142
Programming Experience
Beginner
I am trying to get all the numbers for each date in the Florida Lottery History , I have written code to successfully get the dates and numbers.
what I would like to know how to do is format it from most recent date with matching numbers to the oldest date with matching numbers...here is the code I have.

public List<string> Get_LottoHistory()
       {
           List<string> historyResults = new List<string>();


           HtmlWeb lottoPage = new HtmlWeb();
           string webToParse = "http://www.floridalottery.com/exptkt/l6.htm";
           HtmlAgilityPack.HtmlDocument historyPage = lottoPage.Load(webToParse);


           HtmlNodeCollection historyNode = historyPage.DocumentNode.SelectNodes("/html/body/table[1]/tr/td");


           if (historyNode != null)
           {
               foreach (HtmlNode item in historyNode)
               {
                   string[] numDate = item.InnerText.Split(' ', '\n', '-');
                   
                   if (numDate.Length > 0)
                   {
                       for (int i = 0; i < numDate.Length; i++)
                       {
                           Regex datePattern = new Regex("[0-9][0-9]/[0-9][0-9]/[0-9][0-9]");
                           Regex numPattern = new Regex(">[0-9][0-9]<|>[0-9]<|>X|[0-9]<");
                           if (datePattern.IsMatch(numDate[i], 0))
                           {
                               historyResults.Add(numDate[i]);
                               
                           }
                           if (numPattern.IsMatch(numDate[i], 0))
                           {
                               historyResults.Add(numDate[i]);
                           }       
                       }
                   }
               }
           }




           return historyResults;
       }


this code gets the data I want but it also gets alot of other data not needed ....so the code goes thru the data and only adds the regex matches which would be the date and numbers....the problem with this is the dates are not in any order
would be helpful if someone could walk me thru a solution.

thank you
-InkedGFX
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,209
Location
Sydney, Australia
Programming Experience
10+
You'll need to convert the text dates to actual DataTime values, which you can do using DateTime.Parse, .TryParse, .ParseExact or .TryParseExact. Once the data is sorted, then you can convert the values back to text if that's required.
 
Top Bottom