谁可以把如果IP地址第一位是0就把0给去掉,比如说有“1.01.01.01”转换成“1.1.1.1”,谁有好办法可以搞定?

解决方案 »

  1.   


    public class TestString
    {    /**
         * @param args
         */
        public static void main(String[] args)
        {
            String str = "1.01.01.01";
            String[] temp = str.split("\\.");
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < temp.length; i++)
            {            sb.append(Integer.parseInt(temp[i]));
                if (i != temp.length - 1)
                {
                    sb.append(".");
                }
            }
            System.out.println(sb.toString());
        }}
      

  2.   


                    String str = "01.101.01.01";
    str = str.substring(0,1).replace("0", "")+ str.substring(1);
    str = str.replaceAll("\\.0", "\\.");   方法比较土,等待高手吧