In ruby, I parse the date in the following format: 24092008. I want to convert each section (year, month, date) into a number.
I split them using a regular expression that creates three lines that I pass to the Integer constructor.
date =~ /^([\d]{2})([\d]{2})([\d]{4})/ year = Integer($3) month = Integer($2) day = Integer($1)
When it hits the line of the month, it crashes as follows:
`Integer': invalid value for Integer: "09" (ArgumentError)
It took me a while to figure out that the interpretation of the leading zero, since Octal and 09 is not a valid Octal number (works fine with "07").
Is there an elegant solution for this, or should I just check for a number less than 10 and remove the zero first?
Thanks.
string date types ruby
Darren greaves
source share