gpt4 book ai didi

java - 如何在 StringBuffer 中使用 replaceAll() 方法?

转载 作者:搜寻专家 更新时间:2023-10-31 20:10:02 26 4
gpt4 key购买 nike

我需要替换字符串缓冲区中的多个单词。所以我在 StringBuffer 中寻找 replaceAll 方法。

那么我们在 StringBuffer 中有它吗?

字符串方法:

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

最佳答案

StringBuffer 上没有这样的方法。也许以下内容会有所帮助:

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);

关于java - 如何在 StringBuffer 中使用 replaceAll() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33880756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com