Click here to Skip to main content
15,917,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai

i am currently working on a chatbot project.
now i would like to do perform some mathematical calculation.
for that i need to recognize the user given number in words (eg: seventy seven) and then convert it to number (77) for processing.
how could i do that for such large set of numbers ? is there any tool or codes available to do this?
ie converting words to number.
plz help
Posted
Updated 3-Jul-11 4:37am
v3

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Jul-11 13:20pm    
It's wonderful how many solved this boring problem!
My 5.
--SA
ya thats a very good solution :
using System.Collections;
protected void button1_Click(object sender, EventArgs e)
{
Hashtable hashTable = new Hashtable();
hashTable.Add("one", "1");
hashTable.Add("two", "2");
hashTable.Add("three", "3");
hashTable.Add("four", "4");
hashTable.Add("five", "5");
hashTable.Add("six", "6");
hashTable.Add("seven", "7");
hashTable.Add("eight", "8");
hashTable.Add("nine", "9");
hashTable.Add("ten", "10");
hashTable.Add("eleven", "11");
hashTable.Add("twelve", "12");
hashTable.Add("thirteen", "13");
hashTable.Add("fourteen", "14");
hashTable.Add("fifteen", "15");
hashTable.Add("sixteen", "16");
hashTable.Add("seventeen", "17");
hashTable.Add("eighteen", "18");
hashTable.Add("nineteen", "19");
hashTable.Add("twenty", "20");
hashTable.Add("thirty", "30");
hashTable.Add("fourty", "40");
hashTable.Add("fifty", "50");
hashTable.Add("sixty", "60");
hashTable.Add("seventy", "70");
hashTable.Add("eighty", "80");
hashTable.Add("ninety", "90");
hashTable.Add("hundred", "100");
hashTable.Add("thousand", "1000");
hashTable.Add("lakh", "100000");
hashTable.Add("crore", "10000000");
string wordValue = TextBox1.Text.Trim().ToLower();
string[] strArray = wordValue.Split(' ');
int value = 0;
int tempValue = 0;
foreach (string s in strArray)
{
if (object.Equals(s, "hundred") || object.Equals(s, "thousand") || object.Equals(s, "lakh") || object.Equals(s, "crore"))
{
value += tempValue * int.Parse(hashTable[s].ToString());
tempValue = 0;
}
else
{
if (hashTable.ContainsKey(s))
{
tempValue += int.Parse(hashTable[s].ToString());
}
}
}
TextBox1.Text = (value + tempValue).ToString();
}
 
Share this answer
 
Comments
Christian Graus 3-Jul-11 23:06pm    
Why would you build the hash table every time, instead of making it a member ?
Shahin Khorshidnia 4-Jul-11 0:49am    
Good +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900