简体   繁体   中英

Conversion of CharSequence to maths expression

In my App i have two TextViews one contains an expression eg. 3 + 4 =

And the second contains an answer eg. 7

How would i go about turning this into a valid maths expression so the app could calculate it and return the answer as an int?

Depending on the complexity of the expressions you expect in your TextViews, you might need to construct a parser/interpreter for them. If that's the case, I heartily recommend ANTLR . For more information about using ANTLR on Android, see this question .

Another parser generator that I know of is JavaCC , but ANTLR is a lot more flexible and powerful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM