Just it, I know how to do it with a string but not with a StringBuilder.
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One way is to use
indexOf()to locate the tags, anddelete()to remove them.See the documentation.
To do this efficiently you would need to use
indexOf(String str, int fromIndex)in a loop to ensure you removed multiple tags – and be careful how you updatefromIndexafter removing a tag! The simpler but inefficient way would be to just callindexOf()repeatedly until you run out of matches, but this would keep restarting the search from the start of the String.Or you could convert the StringBuilder to a String, create a new String with the tags removed using
replaceAll(), then create a new StringBuilder with the result. Although this initially seems unnecessarily ugly and inefficient, it’s probably less code, and clearer to read, if efficiency is not a priority.