[align=center]String str = "aaa<2222>;bbb<3333>;cccc<5555>;cccc<666>;";   如何截取括号之间的值。[/align]

解决方案 »

  1.   

    可以先用split(";")这个函数根据分号将其全部分开,保存在数组里面;
    然后再用正则表达式去匹配<>之间的数字。
      

  2.   

    分开保存到数组中之后,直接可以用<>括号去分离
      

  3.   

    public static void main(String[] args) {
      String s = "aaa<2222>;bbb<3333>;cccc<5555>;cccc<666>;";
      String[] arr = s.split(";");
      String[] arr1 = new String[arr.length];
      for (int i = 0; i < arr.length; i++) {
           System.out.println(arr[i]);
           arr1[i] = "";
    for (int j = 0; j < arr[i].length(); j++) {         if (arr[i].charAt(j)== '<'){

    while(arr[i].charAt(++j) != '>') {
    arr1[i] = arr1[i] + arr[i].charAt(j);
    }
    } }
     System.out.println(arr1[i]);
    }}输出结果:
    aaa<2222>
    2222
    bbb<3333>
    3333
    cccc<5555>
    5555
    cccc<666>
    666
      

  4.   

    String  str = "aaa<2222>;bbb<3333>;cccc<5555>;cccc<666>;";
    Pattern peg = Pattern.compile("[^<]+(?=>)");
    Matcher mat = peg.matcher(str); 
    while(mat.find()){ ................}