posted 20 years ago
There may not be an elegant way to pull this off. You could use a combination of Maps and Regexes that employ capturing groups but anyway you slice it the logic gets nasty. For example English has numbers like eleven, twelve, fifteen, eighteen which would have to be handled with logic separate from teens like fourteen, sixteen, seventeen which could be handled in a similar manner to twenty one, twenty two, twenty three by dropping the white space (or dash) between the words. Then there would need to be logic that allowed one, two, three, etc to stand alone or to only follow twenty, thirty, forty, etc and reverse that for twenty, thirty, forty, etc. If you used two capturing groups for some of the teens, then you would need to check for those that do not comply as mentioned above. And one must be allowed to precede hundred.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher