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

string[] strArray = new string[] {"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN" };

at run time i want to convert this string to equivalent integer.
here i mentioned Ten charactors only
but run time my input will be greater than "Ten"

i want output like this
"ONE" - 1
"TWO" - 2
"THREE" - 3
"FOUR" - 4
"FIVE" - 5

is there any way to convert in c#...?
Posted
Comments
Raul Iloc 27-Mar-14 3:06am    
Did you try my solution?

1 solution

If your data are predefined, you should use enum like in the code bellow, otherwise I see no solution posible:
C#
public enum NumericStrings : int
{
ZERO = 0,
ONE = 1,
TWO = 2,
ELEVEN = 11,
...
}
//The usage
string myVar = "ELEVEN"
//the conversion will be simple:
NumericStrings temp = (NumericStrings) Enum.Parse(typeof(NumericStrings), myVar);
int myInt = (int)temp; // Here is the result!
 
Share this answer
 
v2

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