Evaluate a string as an integer

  • Thread starter Thread starter MN
  • Start date Start date
M

MN

Hi All,

I have a string like ...

String str1 = "(15*20)+12.5";

I want to evaluate this string to get the mathematical output. Ideally
output will be 312.5. How can I do with the .Net??

thanks

Manoj
 
I think you have to split the string into pieces, convert the numbers to
numbers. you also have to extract the operators, and then write a function
which calculates this things the right way...
 
you can you microsoft script control

MMScriptControl.ScriptControl s = new MMScriptControl.ScriptControl();
s.Language="VBScript";
string str1 = "(15*20)+12.5";
double r = s.Eval(str1);

you must add a reference to the ocx microsoft script control library
 
double r=(double)s.Eval(...);
....


you can you microsoft script control

MMScriptControl.ScriptControl s = new MMScriptControl.ScriptControl();
s.Language="VBScript";
string str1 = "(15*20)+12.5";
double r = s.Eval(str1);

you must add a reference to the ocx microsoft script control library
 
Back
Top