Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: Words to NSNumber

I want to convert words into number like Ninety Nine to 99 Second to 2nd and Two to 2 etc

Does anybody knows how to do that?

like image 833
Ayaz Alavi Avatar asked Jan 15 '23 17:01

Ayaz Alavi


1 Answers

There is no API from Apple for this kind of purpose. Lexicographical analysis is hard even if it is just for a single language. Expressing a number as words might be relatively simple, but getting from words to numbers would require dealing with many special cases.

The brute force approach would be to have a database of all the various possible combinations. A smarter approach would probably analyse the individual words and reason what number that could mean.

like image 89
Cocoanetics Avatar answered Jan 20 '23 09:01

Cocoanetics