473,382 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 2451
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: NotGiven | last post by:
I have the code below that always evaluates to true. Why and what do I do about it? Many thanks in advance! In the code, I have tried sending in the URL ?indentNum=23 ?indentNum=23.2...
8
by: David Morris | last post by:
OK, this is for you experienced Java programmers out there. I have a string that contains the following value: "myValue += 5" I need, in Java, to be able to evaluate this expression. ...
1
by: David Laub | last post by:
I have no problems running the following dynamic XPath evaluator form MSXSL: <msxsl:script implements-prefix="dyn" language="jscript"> evaluate(context, expression) { return...
19
by: Mark A. Odell | last post by:
Is NULL guaranteed to evaluate 'not true', e.g. is it completely safe and portable to write: char *pFoo = malloc(1024); if (pFoo) { /* use pFoo */ free(pFoo); }
13
by: Zeng | last post by:
Hello, Please help!!! I've been stuck on this issue for months. I just wonder if there is a way to programmatically evaluate expression strings such as ( ( 3 + 5 ) / 2 ) > 4 --> this...
15
by: Phlip | last post by:
Javascripters: I have an outer page and an inner iframe. The outer page calculates some javascript, and wants the inner frame to run it. The inner frame should hit a page on the same (private)...
2
kadghar
by: kadghar | last post by:
Many people asks if there is a way to write a mathematical expression, writen as a string in a text box, so they can do something like: sub something_click() textbox2.text=eval(textbox1.text)...
2
by: yarborg | last post by:
This is kind of a weird one and hard to find answers online because of the format of the question. Essentially I want to be able to have a string that looks like this "True AND True AND True" and...
1
by: aitia | last post by:
this the code. i used ECLIPSE to run this.. it has some codes smells that i can't seem to figure out.. can any one help? import java.io.*; import java.util.*; public class Postfix { private...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.