The pseudo-code could be:
- When appending on the expression*
- if the character being appended is an operator then remove it
- append the new character to the expression
Considering the first line of our pseudo-code, a good place to implement this might be in the appendOnExpression method since that method is already responsible for knowing how to properly update the expression on new input–the logic for inputting repeated operators naturally fits into this responsibility.
I’d recommend experimenting with strings on Kotlin Playground. The Kotlin Koans and other beginner tutorials should also help with learning string manipulation.
EDIT: From looking at your stackoverflow question and seeing as you’re asking for the full implemented code completed for you, I want to double down on encouraging you to go through some of the basic tutorials. It’ll be a million times faster to learn and understand what your code is doing. The example you’re asking does not require anything complicated or even Android related–it’s beginner string manipulation and we all have to learn it at some point.
It’s possible that within an hour of following a tutorial and experimenting on Kotlin Playground you could answer this question yourself and fully understand why your answer would be correct.
Feel free to ask for learning resources if those tutorials assume too much prior programming experience.