472,096 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 software developers and data experts.

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 2388
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.