Jam*_*ron 6 c# lambda parsing expression
我从其他人编写的配置文件中读取了一个逻辑字符串,其中包含如下表达式:
(VALUE_1)OR((NOT(VALUE_2))AND(NOT(VALUE_3)))
Run Code Online (Sandbox Code Playgroud)
但是,对于从哪里开始解析它并比较我在其他地方存储为相同字符串名称的变量的值,我有点困惑。我认为需要使用 LambdaExpression 是否正确?字符串是否需要以某种方式拆分并作为组成部分而不是整体进行分析?
编辑:
似乎Flee做了我需要它做的事情,我可以在使用该库评估表达式之前将 VALUE_x 的名称定义为 true 或 false。
我认为您可以将字符串转换为单词数组,然后根据存储的变量检查每个单词。
//Convert the string into an array of words
string[] source = line.Split(new char[] { '.', '?', '!', ' ', ';', ',','(',')' }, StringSplitOptions.RemoveEmptyEntries);
// Create and execute the query. It executes immediately
// because a singleton value is produced.
// Use ToLowerInvariant to match "data" and "Data"
var matchQuery = from word in source
where word.ToLowerInvariant().Contains("your stored variable elsewhere")
select word;
// Count the matches.
int varCount = matchQuery.Count();
Run Code Online (Sandbox Code Playgroud)
使用匹配查询来处理匹配的变量名称。
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
5575 次 |
| 最近记录: |