Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:48:21+00:00 2026-06-08T02:48:21+00:00

Possible Duplicate: Is there a string math evaluator in .NET? I need to implement

  • 0

Possible Duplicate:
Is there a string math evaluator in .NET?

I need to implement mathematical expression parser. It has to evaluate the following expressions:

  • Basic operators(+,-,*,/,%[modulo operator])
  • priority operations such as 2*(4-1)
  • sin,cos,tan,cotan, log(base,number) functions
  • allows compositions such as sin(cos(log(2,32)))
  • power operation such as 2^5

First that I wanted to use JScript eval function. But it’s not unsafe and no power operator. Secondary I searched for some libraries in Internet. But as turned out, I cannot use them. So the question is the following: how safe is JScript eval function calling and are there any standard .net tools for my task? If not, which algorithm is the best? As of now I’m trying to build expression tree and then compile it to get result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:48:23+00:00Added an answer on June 8, 2026 at 2:48 am

    You can try NCalc

    Dictionary<string, int> dict = new Dictionary<string, int>() {
        {"a",1} ,
        {"b",4}
    };
    
    NCalc.Expression exp = new NCalc.Expression("a + b / 2 * myfunc(3.14)");
    
    exp.EvaluateFunction += (s, e) =>
        {
            var d = (double)e.Parameters[0].Evaluate();
            e.Result = Math.Cos(d);
        };
    
    exp.EvaluateParameter += (s, e) =>
        {
            e.Result = dict[s];
        };
    
    var result = exp.Evaluate();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: Is there a string math evaluator in .NET? Converting string expression to
Possible Duplicate: Differences in string compare methods in C# In .NET there are many
Possible Duplicate: Java: Parse a mathematical expression given as a string and return a
Possible Duplicate: How to detect the presence of URL in a string Is there
Possible Duplicate: Concatenate Two NSDate String values Just confused that is there any default
Possible Duplicate: C++ char* vs std::string Is there any advantage to using char*'s instead
Possible Duplicate: String vs string in C# I know there is no difference between
Possible Duplicate: Why is String final in Java? There are various moments in my
Possible Duplicate: Is there a “Set” data structure in .Net? Duplicate: this is a
Possible Duplicate: Differences in string compare methods in C# Is there any difference between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.