gpt4 book ai didi

java - 将字符串中的特定字母/空格更改为另一个字母/空格

转载 作者:行者123 更新时间:2023-12-03 02:25:29 25 4
gpt4 key购买 nike

是否可以更改字符串中的特定数字/字母甚至空格并将其设置为另一个?

示例:

String test = "name1 name2 name3 name4"

我想将它转换成另一个字符串,这样它看起来像这样:

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

那么我怎样才能告诉它把所有“空格”设置为+呢?

最佳答案

使用replaceAll()

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

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

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