不能更改string中的特定数字/字母或空格,并将其设置为另一个吗?

例:

String test = "name1 name2 name3 name4"


我想将其转换为另一个String,使其看起来像这样:

String test2 = "name1+name2+name3+name4"


那么如何告诉它将所有“空格”设置为+?

最佳答案

使用replaceAll()

test2=test.replaceAll("\\s","+");

关于java - 将特定的字母/空格从字符串更改为另一个,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22215801/

10-11 04:09
查看更多