有字符串"http://www.aa.com/php/index.php?number=100&tag=100"我想提取number=后面的数字该怎么提取亚

解决方案 »

  1.   


    String res = str.spilt("=");
    // res[1] 就是你想要的
      

  2.   

    也可以正则表达。
    Pattern pattern = Pattern.compile(""^(-?\d+)(\.\d+)?$");
    Marcher marcher = pattern.macher(str);
    while(marcher.find()){
    System.out.println(marcher.group());
    }
      

  3.   

    二楼的结果不对吧,这样的话res[1]为100&tag
      

  4.   

    StringUtils.substringBetween(url,"number=","&tag");
      

  5.   

    String res = str.spilt("=").spilt("&");
    // res[0] 就是你想要的
      

  6.   

    4楼说的也有问题吧。String类没有subStringBetween这个方法。5楼用  String res = str.spilt("=").spilt("&");编译也通不过。
            因为str.split("=")返回的是一个字符串数组,不能对它使用split方法。
      

  7.   

    截取等号后面的字符串然后遍历你想要的数据
    String[] res = str.spilt("=");
    for(int i=0;i<res.lenght;i++){
      String a=res[i];
    }
      

  8.   


    String s = "http://www.aa.com/php/index.php?number=100&tag=100";
    String result = s.substring(s.indexOf("number=")+7,s.indexOf("&tag="));
    System.out.println(result);
      

  9.   

    因为我是在一个文件中写入正则表达式,然后读取这个表达式,从给定的字符串中提取出number=后面的数字,可是我不知道这个正则表达式该怎么写
      

  10.   

    我说了用String类了么,
    没看见用的是StringUtils类么
      

  11.   


    public static void main (String args[]) {
    String str = "http://www.aa.com/php/index.php?number=120&tag=100";
    int a = Integer.parseInt(str.replaceAll(".*number=(\\d+).*", "$1"));
    System.out.println(a);
    }
      

  12.   

    String src = "http://www.aa.com/php/index.php?number=100&tag=100";
    String regex = "number=(\\d+)&";
      Matcher matcher = Pattern.compile(regex).matcher(src);
      if(matcher.find())System.out.println(matcher.group(1));
      

  13.   

    先用?分割得到后面的,其次是用&,最后用=分割