开发者

How to convert text to arithmetic expression

开发者 https://www.devze.com 2023-03-07 10:47 出处:网络
I want to build开发者_Python百科 text base calculator in c# Let suppose I have text Add two plus three. its arithmetic

I want to build开发者_Python百科 text base calculator in c#

Let suppose I have text

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)

And so on.

What will be the algorithm to do this?


May be you have to do parsing of your text. The idea is to find out tokens(text of interest) from you string. Lets suppose, the text is Add two plus three, you find separate tokens, lets say the tokens you find are Add, two, plus, three. Replace tokens with your predefined numbers, for example token two = 2 and so on. Replace arithematic text with arithematic operators for example Add = + and so on. And finally execute the calculated expression to get the result.

0

精彩评论

暂无评论...
验证码 换一张
取 消