c# - 如何将文本转换为算术表达式

标签 c# algorithm

我想在 C# 中构建基于文本的计算器

假设我有文本

Add two plus three. its arithmetic expression will be (2+3)

Add five thousand two hundred to four hundred thirty two divided by thirty four.((5200+430)/34).

Add three million to seven million then add five then two.(((3000000+7000000)+5)+2)

等等。

执行此操作的算法是什么?

最佳答案

可能您必须对文本进行解析。这个想法是从你的字符串中找出标记(感兴趣的文本)。假设文本是 Add two plus three,您找到单独的标记,假设您找到的标记是 Add, two, plus, three。将标记替换为您预定义的数字,例如标记 two = 2 等等。用算术运算符替换算术文本,例如 Add = + 等。最后执行计算出的表达式得到结果。

关于c# - 如何将文本转换为算术表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6089598/

相关文章:

c# - INotifyPropertyChanged PropertyChangedEventHandler 事件始终为 null

c# - 加密异常 : 'Invalid algorithm specified' when using SHA-512

c# - "Logging out"用户关闭浏览器事件

algorithm - 在集合中寻找模式

algorithm - 很少有物体在 Unity 中一个一个地直线移动

c# - 如何拖动 DataPoint 并将其移动到 Chart 控件中

c# - 无法以代码优先方式创建数据库 Entity Framework

algorithm - 归并排序算法困境

php - Array to SVG,灵活的PHP算法

python - 基于时间的算法中的优化