Replace all in StringBuffer

I have a StringBuffer object, in the following value is repeated at several places.
<?xml version="1.0" encoding="UTF-8"?>
I want to replace all these values with a blank. I can't see a replaceAll function in StringBuffer. Can you please let me know how to do this?
Who is Participating?
marchentConnect With a Mentor Commented:
what about convert the string buffer into string, the perform replaceAll, and then return back to string buffer?
StringBuffer sb = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>blablablabaa<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
String replaceStr = "<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>";
sb = new StringBuffer( sb.toString().replaceAll(replaceStr, "") );

Open in new window

CEHJConnect With a Mentor Commented:
You need to turn it into a String first
(that is if you don't want to use )

Use StringBuilder in preference to StringBuffer where you can
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.