VB.Net- Evaluating Mathematical Expression in a String
Asked Answered
F

1

9

Is there a method that allows me to evaluate a mathematical expression in a string? Example (Not actual Code):

Input = "2+2"

Output = SomeMethod(Input)

Output = 4

Update: Nevermind, I found a way around it by using DataTable.Compute.

Forever answered 7/7, 2011 at 1:19 Comment(2)
Search SO for MSScriptControl.Ditheism
Possible duplicate of Doing math in vb.net like Eval in javascriptAlvinalvina
H
3

You'll need a math expression parser to handle this.

Here are some various open source options on CodePlex:

A search will find many others...

Hereabouts answered 7/7, 2011 at 1:22 Comment(3)
Thanks for the input but are there any libraries in the .Net that can do this? I'd prefer not to use an external parser...I don't need anything complex as long as it can add, subtract, multiply, and divide.Forever
@Leonardo: Not directly. You can use CodeDom to generate this yourself, but it's a fair amount of work...Hereabouts
Hmmm I think I'll use CodeDom instead then, thanks for the helpForever

© 2022 - 2024 — McMap. All rights reserved.