求助:得到这样的字符串{{11,12,13},{21,22,23},{31,32,33}}
怎么转化成数据呢 String[][]s={{"11","12","13"},{"21","22","23"},{"31","32","33"}};
??
谢谢

解决方案 »

  1.   

    通过下标,获取一个值,这个值 是string类型,将它转化为int类型
      

  2.   

    String 的split方法,或者tokennizer 方法 先截取出{11,12,13}   {21,22,23}   {31,32,33} 三个部分
    然后对每个部分再截取
      

  3.   


    public class StringToArray {
    public static void main(String[] args) {
    String str = "{{11,12,13},{21,22,23},{31,32,33}}";
    str = str.replaceAll("\\},\\{", ";");//用分号替换掉中间的“},{”
    str = str.replaceAll("\\{\\{","").replaceAll("\\}\\}", "");//替换掉“}}”和“{{”

    String[] temp1,temp2;
    temp1 = str.split(";");
    String[][] s = new String[temp1.length][];
    for(int i=0; i<temp1.length; i++) {
    temp2 = temp1[i].split(",");
    s[i] = new String[temp2.length];
    for(int j=0; j<temp2.length; j++) {
    s[i][j] = "\"" + temp2[j] + "\"";
    }
    }

    for(int i=0; i<s.length; i++) {
    for(int j=0; j<s[i].length; j++) {
    System.out.print(s[i][j] + " ");
    }
    }
    }
    }