ncalc / ncalc

NCalc is a fast and lightweight expression evaluator library for .NET, designed for flexibility and high performance. It supports a wide range of mathematical and logical operations.
https://ncalc.github.io/ncalc/
MIT License
697 stars 86 forks source link

occur exception when using chinese characters in parameters #348

Closed wapco closed 1 month ago

wapco commented 1 month ago

Hi, i get this exception when using chinese characters in parameters:

    string exp = "2 * 参数1";
    Expression e = new Expression(exp);
    e.Parameters["参数1"] = 5;
    var v = e.Evaluate();

exception: NCalc.Exceptions.NCalcParserException: Error parsing the expression. ---> NCalc.Exceptions.NCalcParserException: Invalid token in expression at position (1:2) at NCalc.Parser.LogicalExpressionParser.Parse(LogicalExpressionParserContext context) at NCalc.Factories.LogicalExpressionFactory.Create(String expression, ExpressionOptions options) at NCalc.Factories.LogicalExpressionFactory.NCalc.Factories.ILogicalExpressionFactory.Create(String expression, ExpressionOptions options) --- End of inner exception stack trace ---

Bykiev commented 1 month ago

Hi, you should use a square brackets in expression with Unicode: string exp = "2 * [参数1]";

wapco commented 1 month ago

It works normally. Thank u!