gpt4 book ai didi

Java replaceALL 字符串

转载 作者:塔克拉玛干 更新时间:2023-11-01 23:09:13 24 4
gpt4 key购买 nike

我有一个字符串:

100-200-300-400

我想将破折号替换为“,”并添加单引号使其变为:

 '100','200','300','400'

我目前的代码只能将“-”替换为“,”,如何加上单引号?

String str1 = "100-200-300-400";      
split = str1 .replaceAll("-", ",");

if (split.endsWith(","))
{
split = split.substring(0, split.length()-1);
}

最佳答案

你可以使用

split = str1 .replaceAll("-", "','");
split = "'" + split + "'";

关于Java replaceALL 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33688258/

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