Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Load of trouble?

From: g:santilli:tiscalinet:it at: 1-Dec-2001 13:08

Hello [Sanghabum--aol--com]! On 30-Nov-01, you wrote: S> I have a raw string entered by a user: S> raw-input: " 12-may-87 " S> It is supposed to be a date (in this case). I want to convert S> it to its internal Rebol format, and see if it is valid. When handling dates, I'd suggest to use TO-DATE instead: it handles much more formats than LOAD and just gives an error if the input is not a date.
>> to-date "12-may-87"
== 12-May-1987
>> to-date "12/5/87"
== 12-May-1987
>> to-date "12 5 87"
== 12-May-1987
>> to-date "1987 5 12"
== 12-May-1987
>> to-date "invalid"
** Script Error: Invalid argument: invalid. ** Where: to date! :value You'll need to TRIM your strings tough:
>> to-date " 12-may-87 "
** Script Error: Invalid argument: 12-may-87 . ** Where: to date! :value Romano's suggestion is useful if the user could input values of different datatypes (imagine accepting a file or an url), but if you know the type in advance, TO is the best IMHO. (Of course, you'll need to do your own checks for certain types, such as all of the any-string!s...) Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/