当前位置: 代码迷 >> Java相关 >> 求解关于由ASII码组成的字符串变换成二进制序列组成的字符串的有关问题
  详细解决方案

求解关于由ASII码组成的字符串变换成二进制序列组成的字符串的有关问题

热度:4594   发布时间:2013-02-25 21:43:09.0
求解关于由ASII码组成的字符串变换成二进制序列组成的字符串的问题

        String phy = null;
         String dat="75 81  73 110 112 117 116 32 116 104 101 32 116";
         String[] strChar=dat.split(" ");

         for(int i1=0;i1<strChar.length;i1++){ 
          phy +=Integer.toBinaryString(Integer.parseInt(strChar[i1]))+" "; 
              } 


编译时抛出异常:Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:504)
at java.lang.Integer.parseInt(Integer.java:527)
at Test.main(Test.java:35)

注:第35行为 phy +=Integer.toBinaryString(Integer.parseInt(strChar[i1]))+" ";

求解各位大神。。。
------最佳解决方案--------------------------------------------------------
这还不简单,你81和73之间,有2个空格,删掉一个就行了
或者
把dat.split(" ");
改成dat.split("\\s+");
------其他解决方案--------------------------------------------------------
引用:
这还不简单,你81和73之间,有2个空格,删掉一个就行了
或者
把dat.split(" ");
改成dat.split("\\s+");
疏疏忽了,谢谢。。。。
  相关解决方案