ExpressionFormatter.Format(string) - YiZhang-Paul/Mock_Up_Calculator GitHub Wiki
Namespace: FormatterClassLibrary
Description: Format expressions represented as string to human-readable format.
Parameters | Description |
---|---|
expression<string> | expression to be formatted, represented as string |
Returns | Description |
---|---|
string | formatted expression |
Exceptions | Cause |
---|---|
NullReferenceException | expression is null |
ArgumentException | expression is not a valid math expression |
Examples:
var unarys = new HashSet<string>() { "fact", "sin", "log" };
var formatter = new ExpressionFormatter(unarys);
Console.WriteLine(formatter.Format("8 % 4")); //8 % 4 since there is no unary operator
Console.WriteLine(formatter.Format("8 % 4 fact")); //8 % fact(4)
Console.WriteLine(formatter.Format("8 + 4 fact sin log")); //8 + log(sin(fact(4)))