7stud -- wrote:
>
> Whoops. I forgot to post a solution for that leading "0" in the month:
>
Here are some better ways:
month = "09"
begin
month = month.to_i(10)
puts month #9
raise ArgumentError if month == 0
rescue ArgumentError
puts "invalid date string"
end
#------------
require "scanf"
str = "2007.09"
year, month = str.scanf("%d.%d")
puts year #2007
puts month #9
str = "20080627"
y, m, d = str.scanf("%4d%2d%2d")
puts y, m, d #2008 6 27
--
Posted via http://www.ruby-forum.com/.