呵呵 简单的小问题呵
int intValue = Integer.parseInt("1024MB");
我想要的返回是1024啊 但是这个会报异常
怎么不能向c中的atoi这样变成1024呢
 
在java中这个改怎么办 怎样让他返回1024 有线程的函数吗
因为输入的字符串是位置的 但都是数字开头谢谢

解决方案 »

  1.   

    不知道你要转换成什么 不过在转换之前把多余的东西过滤掉不就完了么?
    int intValue = Integer.parseInt("1024MB".replace("MB",""));
      

  2.   

    String[] a=参数字符串.toCharArray();
    String b="";
    int i=0;
    while(true){
       try{
          b= b+Integer.parseInt("a[i]").toString;
        } catch (Exception e) {
          int intValue = Integer.parseInt(b); 
           return intValue;
        }
    }
      

  3.   

    String[] a=参数字符串.toStringArray(); 
    String b=""; 
    int i=0; 
    while(true){ 
      try{ 
          b= b+Integer.parseInt("a[i]").toString; 
        } catch (Exception e) { 
          int intValue = Integer.parseInt(b); 
          return intValue; 
        } 

    这个呢。
      

  4.   

    String[] a=参数字符串.toStringArray(); 
    String b=""; 
    int i=0; 
    while(true){ 
      try{ 
          b= b+Integer.parseInt("a[i]").toString;
          i++; 
        } catch (Exception e) { 
          int intValue = Integer.parseInt(b); 
          return intValue; 
        }
        
    }
    int intValue = Integer.parseInt(b); 
    return intValue; 刚才居然忘了i++。。
      

  5.   

    比较麻烦,把string放char数组里面,循环判断是不是是不是在0-9的数字范围内。不是就截到上一个为止。再Integer.parseInt(String)
      

  6.   

    public static void main(String[] args) {
    System.out.println(Pattern.compile("\\D+").split("1232dsf")[0]);
    System.out.println(Pattern.compile("\\D+").split("0123fmd")[0]);
    System.out.println(Pattern.compile("\\D+").split("8883dsess")[0]);
    }
    1232
    0123
    8883
      

  7.   

    \\d什么意思?
    不是\d匹配数字么?
    \\d不限数量匹配数字?
      

  8.   

    这个贴不先结 等待梦里楚香 最后的回答和confirm
    崇拜啊