How do I remove the previously appended strings to my String Builder? If I have for example
result.append("$10.00");
result.append("+" + "$20.00");
result.append("+" + "$5.00");
How do I remove $5 and $20 respectively from a string which is now "$10.00 + $20.00 + $5.00"?
Once you append it, it becomes "one" and you cant reverse
However you can use this in this case :
result.delete(result.lastIndexOf("+"), result.length());
There is no immediate way to do this. I suggest you append each substring to a List or even to a Stack, and pop whatever you don't need out of your data structure. When you are totally sure about what to present in your StringBuilder, start appending to it by running through your Collection and putting each substring into your final StringBuilder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With