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?
alice20Asked:
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, "") );
System.out.println(sb);

Open in new window

0
 
CEHJConnect With a Mentor Commented:
You need to turn it into a String first
0
 
CEHJCommented:
(that is if you don't want to use http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#matcher(java.lang.CharSequence) )

Use StringBuilder in preference to StringBuffer where you can
0
 
CEHJCommented:
:-)
0
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.