469,636 Members | 1,544 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

Evaluate a string as an integer

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

Nov 16 '05 #1
5 2329
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...

MN wrote:
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

Nov 16 '05 #2
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

"MN" <mn*********@hotmail.com> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP10.phx.gbl...
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


Nov 16 '05 #3

double r=(double)s.Eval(...);
....
<e> ha scritto nel messaggio news:eJ*************@TK2MSFTNGP12.phx.gbl...
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

"MN" <mn*********@hotmail.com> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP10.phx.gbl...
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



Nov 16 '05 #4
Hi,
Here is a link to the code written in vb6 which does exactly what you
are looking for. You can study it and convert it to C#

http://www.developerfusion.com/show/216/

Regards
Benny

MN wrote:
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



Nov 16 '05 #5
MN
Hi,
Thanks All

Manoj

<e> wrote in message news:ux**************@TK2MSFTNGP09.phx.gbl...

double r=(double)s.Eval(...);
...
<e> ha scritto nel messaggio news:eJ*************@TK2MSFTNGP12.phx.gbl...
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

"MN" <mn*********@hotmail.com> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP10.phx.gbl...
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




Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by NotGiven | last post: by
8 posts views Thread by David Morris | last post: by
19 posts views Thread by Mark A. Odell | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.