I know you can check if a string is an integer by just doing Integer.parseInt("1234");
But what I want is to do is link a textual number to an integer.
i.e.
Is there some library I can use to do this, or do I have to program this all by hand?
The reason I want to do this, is that I have an android application with speech recognition.
The user can then count. This number is shown on the screen.
EDIT
After some experimenting, I figured out that the SpeechRecognizer class I use automatically parses numbers to actual numbers...
Using built-in method isdigit(), each character of string is checked. If the string character is a number, it will print that string contains int. If string contains character or alphabet, it will print that string does not contain int.
To check if a string is integer in Python, use the isdigit() method. The string isdigit() is a built-in Python method that checks whether the given string consists of only digits.
Use the isDigit() Method to Check if String Contains Numbers in Java. To find an integer from a string, we can use this in-built function called isDigit() .
Python String isnumeric() Method The str. isnumeric() checks whether all the characters of the string are numeric characters or not. It will return True if all characters are numeric and will return False even if one character is non-numeric.
I am not sure if there is a library for that but here is a good example.
As far I know there is no library for this but you can think like this
create three types of tokens
a. one, two, three.................... nine
b. eleven to nineteen, twenty, thirty , ............ ninety
c. hundred, thousand, ........ and bigger values
now parse your input string and match with your tokens. Just for a basic idea you can think like this
step 1. create tokens from stirng tokenizer
step 2. match the right most string and match with tokens
step 3. match one by one string from right and match with tokens and calculate
for example ONE THOUSAND FIVE HUNDRED FIFTY THREE
let sum =0
first string = THree so sum +=3
second string = FiFTY so sum += 50;
third string = Hundred so you need to multiply fourth string with 100 and add so sum += f*100.. and so on
This is just a basic idea. So you can implement it perfectly after proper planning
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With