【发布时间】:2022-01-26 23:36:39
【问题描述】:
我的代码如下。在将 DD 附加到字符串后,我需要为字符串中的每个单词添加单引号。
public class Main
{
public static void main(String[] args) {
String ChkboxIds = "'a1b2c3','321cba','123abc'";
String checkBoxId = null;
String checkId = null;
StringBuilder checkIDS = new StringBuilder("'");
for(int i=0;i<=ChkboxIds.split(ChkboxIds, ',').length;i++){
checkBoxId = "DD"+ChkboxIds.split(",")[i].replace("'","")+","+checkBoxId;
checkId = checkBoxId.substring(0, checkBoxId.length() - 5);
System.out.println("---PRINT---"+checkId);
for(int j=0;j<i;j++){
checkIDS..append('\'').append(checkId.split(",")).append('\'').append(',');
System.out.println("---PRINT123----"+checkIDS);
}
}
}
}
我也尝试过使用 StringBuffer。请在此处指出您的答案。我得到的输出是一些垃圾数据,而我需要在开头附加 dd 的单词。
预期输出:'DDa1b2c3','DD321cba','DD123abc'
【问题讨论】:
-
checkIDS..append('\'').append(checkId.split(",")).append('\'').append(',');第一个追加前有2个点,删除一个 -
什么是“垃圾数据”?
-
你需要显示你得到的输出。
-
感谢您的评论,但问题不是点,而是有关点的代码中的错误。我所说的垃圾数据是:'[Ljava.lang.String;@d70c109',....
-
嗨,OP。让我们知道任何答案是否有帮助。如果它回答了您的问题,请接受它。这样其他人就知道你已经(充分地)得到了帮助。另见What should I do when someone answers my question?
标签: java string append output stringbuffer