【发布时间】:2016-01-13 05:09:59
【问题描述】:
我目前正在制作一个计算器。我知道如何编写逻辑,但我很好奇它是否可以按照我将要解释的方式完成。
String str = "12 + 43 * (12 / 2)";
int answer;
answer = str.magic();
//str.magic is the same as
answer = 12 + 43 * (12 / 2);
现在我想要的是如何将 str 转换为可执行代码。
【问题讨论】:
-
是的,可以做到。谷歌表达式解析器
-
我有点困惑——你想问什么?您说您“知道如何编写逻辑”,但随后又问您如何实际执行任务?
标签: c#