【问题标题】:How to do a split in java? [closed]如何在java中进行拆分? [关闭]
【发布时间】:2017-04-14 13:29:59
【问题描述】:

我做了一个 string.split,然后调用了数组的第一个位置,但由于某种原因,所有的数组结果都出现了。这是我的代码

try {
    String xx = "";

    for (int i = 0; i < row; i++) {
        for (int c = 0; c < col; c++) {
            Cell z = s.getCell(c, i);

            xx = xx + z.getContents() + "\n";
        }

        xx = xx + "\n";

    }
    //I do the split here but the result[0] = all the information
    String result[] = xx.split(",");
    textView.setText(result[0]);
} catch (Exception e) {

}

这是输出的图像: Description of the output

【问题讨论】:

  • 你没有在Strings之间添加,
  • 那么你能帮帮我吗?
  • z.getContents() 返回的字符串格式是什么?举个例子String
  • text\text2....我放了输出的图片
  • 如果字符串没有逗号,你为什么指望.split(",") 做任何事情?

标签: java arrays split


【解决方案1】:

尝试使用\\\\ 进行拆分。喜欢

String exampleString = "A\\B\\C\\D"; //escaping the "\" character
String array[] = exampleString.split("\\\\");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 2017-05-05
    • 2021-04-01
    • 2021-05-06
    • 2014-03-10
    • 1970-01-01
    • 2011-03-05
    相关资源
    最近更新 更多