我想在两个分号(:)之间拆分一个字符串。 即,
布尔兰:咖啡先生 - 召回:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980
我正在尝试
split("[\\:||\\:]");
但它不起作用
答案 0 :(得分:3)
使用split以“:”作为正则表达式。
更确切地说:
String splits[] = yourString.split(":");
//splits will contain:
//splits[0] = "BOOLEAN";
//splits[1] = "Mr. Coffee - Recall";
//splits[2] = "8a42bb8b36a6b0820136aa5e05dc01b3";
//splits[3] = "1346790794980";
答案 1 :(得分: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);
}
答案 2 :(得分:0)
这:
String m = "BOOLEAN: Mr. Coffee - Recall:8a42bb8b36a6b0820136aa5e05dc01b3:1346790794980";
for (String x : m.split(":"))
System.out.println(x);
返回
BOOLEAN
Mr. Coffee - Recall
8a42bb8b36a6b0820136aa5e05dc01b3
1346790794980
答案 3 :(得分: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]);
}