Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi I have This String :
C#
string f = "A=(C*D)+(L*K)*B";

And Replace Character With Number.so I Have :
C#
f = "A=(10*12)+(14*15)*13";


How To Convert f To Int?
Posted
Updated 20-May-14 22:59pm
v3
Comments
Kornfeld Eliyahu Peter 21-May-14 3:59am    
What you really want is to compute the result, isn't it?
Karen Mitchelle 21-May-14 4:04am    
Why do you want to use String if you can declare f as int?
It will make that code easier.

PS. Why do you want to make it like that by the way?

Google is your friend: "Expression Evaluator C#"[^].
 
Share this answer
 
C#
string f = "A=(C*D)+(L*K)*B";
f =  f.Replace("C", "10"); // replace for each character like this 
 
Share this answer
 
To solve your problem, you could use a lookup table:
C#
Dictionary<string,> dictionary = new Dictionary<string,>();
	dictionary.Add("C", 10);
	dictionary.Add("D", 12);
        dictionary.Add("L", 14);
        dictionary.Add("K", 15);
        dictionary.Add("B", 13);

And then in a loop to change all letters to numbers
C#
if (dictionary.ContainsKey("С"))
{
    int value = dictionary["С"];
}

Good luck!
 
Share this answer
 

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