Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Getting Started

Coding Seb edited this pageJan 22, 2021 ·10 revisions

Installation

Install the following nuget package :

Install-Package CodingSeb.ExpressionEvaluator

See on Nuget.org

or copy theCodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs file in your project :

Basic C# usage

Simple expressions

usingCodingSeb.ExpressionEvaluator;//...stringexpression;//...ExpressionEvaluatorevaluator=newExpressionEvaluator();Console.WriteLine(expression);Console.WriteLine(evaluator.Evaluate(expression));

Results with some expressions :
Live examples here

1+122 + 3 * 28(2 + 3) * 210Pi3.14159265358979Pow(2, 4)16Sqrt(2) / 30.471404520791032"Hello" + " " + "World"Hello WorldMax(1+1, 2+3, 2*6, Pow(2, 3))12Array(2, $"Test { 2 + 2 } U", true).Length3Array(2, $"Test { 2 + 2 } U", true)[1]Test 4 UArray(2, $"Test { 2 + 2 } U", true)[2] ? "yes" : "no"yesfalse ? "yes" : "no"no"Hello\nWorld"HelloWorld@"Hello\nWorld"Hello\nWorldRegex.Match("Test 34 Hello/-World", @"\d+").Value34int.Parse(Regex.Match("Test 34 Hello/-World", @"\d+").Value) + 2363 / 213d / 2d1.5(float)3 / (float)21.5// use new as a functionnew(Random).Next(1,10)4 // or a random value between 1 and 9// or as a keywordnew Regex(@"\w*[n]\w*").Match("Which word contains the desired letter ?").ValuecontainsList("Test", "Hello", "Bye", "How are you?").Find(t => t.Length < 4)Byenew List<string>(){ "Test", "Hello", "Bye", "How are you?" }.Find(t => t.Length < 4);ByeEnumerable.Range(1,4).Cast().Sum(x =>(int)x)10Enumerable.Repeat(3,6).Cast().ToList().Count6Enumerable.Repeat(3,6).Cast().ToList()[4]3((x, y) => x * y)(4, 2)8"Hello"[2] == 'l'true"Hello,Test,What".Split(ArrayOfType(typeof(char), ',')).Length3"Hello,Test,What".Split(ArrayOfType(typeof(char), ','))[0]Hello"Hello,Test,What".Split(ArrayOfType(typeof(char), ','))[1]Test"Hello,Test,What".Split(ArrayOfType(typeof(char), ','))[2]What"Hello,Test,What".Split(new char[] {','}).Length3"Hello,Test,What".Split(new char[] {','})[0]Hello"Hello,Test,What".Split(new char[] {','})[1]Test"Hello,Test,What".Split(new char[] {','})[2]Whatnew System.Xml.XmlDocument().FluidLoadXml("<root><element id='MyElement'>Xml Content</element></root>").SelectSingleNode("//element[@id='MyElement']").InnerXmlXml Content// if System.Net Assembly is referenced in your project.$"https://www.google.ch/search?q={System.Net.WebUtility.UrlEncode("request with url encode() ?")}"https://www.google.ch/search?q=request+with+url+encode()+%3F

Small scripts

usingCodingSeb.ExpressionEvaluator;//...stringscript;//...ExpressionEvaluatorevaluator=newExpressionEvaluator();Console.WriteLine("--------------------------------------------");Console.WriteLine(script);Console.WriteLine("---------------- Result --------------------");Console.WriteLine(evaluator.ScriptEvaluate(script));

Results with some scripts :
Live examples here

--------------------------------------------x = 0;result = "";while(x < 5){    result += $"{x},";    x++;}result.Remove(result.Length - 1);---------------- Result --------------------0,1,2,3,4--------------------------------------------result = "";for(x = 0; x < 5;x++){    result += $"{x},";}result.Remove(result.Length - 1);---------------- Result --------------------0,1,2,3,4--------------------------------------------x = 0;y = 1;result = 0;if(y != 0){    return 1;}else if(x == 0){    return 2;}else if(x < 0){    return 3;}else{    return 4;}---------------- Result --------------------1--------------------------------------------x = 0;y = 0;result = 0;if(y != 0){    return 1;}else if(x == 0){    return 2;}else if(x < 0){    return 3;}else{    return 4;}---------------- Result --------------------2--------------------------------------------x = 5;y = 0;result = 0;if(y != 0){    return 1;}else if(x == 0){    return 2;}else if(x < 0){    return 3;}else{    return 4;}---------------- Result --------------------4--------------------------------------------Add = (x, y) => x + y;return Add(3, 4);---------------- Result --------------------7--------------------------------------------Add = (x, y) => {    var result = x + y;    return result;};return Add(3, 4);---------------- Result --------------------7

To see more scripts examples see scripts uses for tests in sub directoriesCodingSeb.ExpressionEvaluator.Tests/Resources

Table Of Content

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp