简体   繁体   中英

How to use replaceAll() method in StringBuffer?

I need to replace multiple words in a string buffer. So I am looking for a replaceAll method in StringBuffer .

So do we have it in StringBuffer ?

String method:

str2 = str1.replaceAll(regex, substr);
// (This is String method, I need like this in StringBuffer)

There is no such method on StringBuffer . Perhaps the following will help:

StringBuffer str1 = new StringBuffer("whatever");
// to get a String result:
String str2 = str1.toString().replaceAll(regex, substr);
// to get a StringBuffer result:
StringBuffer str3 = new StringBuffer(str2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM