0

我想在两个分号 (:) 之间分割一个字符串。IE,

布尔值:咖啡先生 - 召回:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980

我在尝试

split("[\\:||\\:]");

但它不工作

4

4 回答 4

3

使用带有“:”的拆分作为正则表达式。

更确切地说:

  String splits[] = yourString.split(":");
  //splits will contain: 
  //splits[0] = "BOOLEAN";
  //splits[1] = "Mr. Coffee - Recall";
  //splits[2] = "8a42bb8b36a6b0820136aa5e05dc01b3";
  //splits[3] = "1346790794980";
于 2012-09-18T09:18:19.543 回答
0

您可以使用split(),参考此代码,

String s ="BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980";

String temp = new String();


    String[] arr = s.split(":");

    for(String x : arr){
      System.out.println(x);
    }
于 2012-09-18T09:18:45.590 回答
0

这:

  String m = "BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980";
  for (String x : m.split(":"))
    System.out.println(x);

返回

BOOLEAN
 Mr. Coffee - Recall
8a42bb8b36a6b0820136aa5e05dc01b3
1346790794980
于 2012-09-18T09:20:10.420 回答
0

正则表达式风味:

    String yourString = "BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980";
    String [] componentStrings = Pattern.compile(":").split(yourString);

    for(int i=0;i<componentStrings.length;i++)
    {
        System.out.println(i + " - " + componentStrings[i]);
    }
于 2012-09-18T09:24:22.097 回答