81,092
社区成员
发帖
与我相关
我的任务
分享
String no = "123,456,789,,,,";
no = no.replace(",,", ", ,");//将两个逗号之间加个空格
String[] nos = no.split(",");
for(int i=0;i<nos.length;i++){
System.out.println("nos["+i+"]:"+nos[i]);
}
String str = ",2011,,,";
str = str.replaceAll(",",", ");
String[] str1 = str.split("\\,");
import java.util.ArrayList;
import java.util.List;
public class Test {
private List templist = new ArrayList();
private String lastS = "";
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String temp = ",2011,,,";
Test test = new Test();
test.getSplitString(temp);
String[] rs = new String[test.templist.size()];
for (int i = 0; i < test.templist.size(); i++) {
rs[i] = test.templist.get(i).toString();
System.out.println(i + "---" + test.templist.get(i).toString());
}
}
private void getSplitString(String x) {
String temp = "";
if (x.contains(",")) {
temp = x.substring(0, x.indexOf(","));
lastS = x.substring(x.indexOf(",") + 1);
templist.add(temp);
if (lastS.contains(",")) {
getSplitString(lastS);
}
}
}
}
乱写,所以不精简,结果在String[] rs
String str = ",2011,,,";
Pattern p = Pattern.compile(".*?\\,");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}
public static void main(String[] args)
{
String str = ",,123,,";
String substr = str;
int count = 0;
while (substr.contains(","))
{
substr = substr.substring(substr.indexOf(",")+1);
count ++;
}
String[] arr = str.split(",", count + 1);
for (int i = 0; i < arr.length; i++)
{
System.out.println(String.format("%s %s", i, arr[i]));
}
}
public class StringSplit {
public static void main(String args[]){
String temp=",2011,,,";
String[] str = temp.split(",", -1);
for(String c : str){
System.out.println("标示开始" + c + "标示结束");
}
}
}