[Newbies] How to test a String if it is a valid date?
Dan Norton
dnorton at mindspring.com
Wed Mar 30 01:57:37 UTC 2016
On 29 Mar 2016 at 19:07, Joseph Alotta wrote:
> Greetings,
>
> I want to test a String to see if it can be a Date using mm/dd/yyyy
> format. I want something that won´t cause a walkback window. Is
> there a String method isValidAsADate?
>
> Sincerely,
>
> Joe.
>
You might have a method like this:
isDate: aString
"Answer whether aString is in the form 'mm/dd/yyyy' "
| w x |
w := aString asString select: [:a | a isDigit or: a = $/].
x := w findTokens: '/'.
^ x size = 3 and: [w = aString]
This is the general idea. Let me know if you have any questions.
- Dan
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
More information about the Beginners
mailing list