String字符串删除开头结尾的数字0

      工作中经常遇到电话号码加拨数字0的情况,这时前台加拨数字0的号码传递到后天就需要把数字0删掉,下面介绍一种简单方便的方法。

package com.xyfer;

public class TestDeleteNumber{
    public static void main(String[] args){
        String number = "000123000456000";
        Stirng regex = "(^0*)|(0*$)";
        System.out.println(number.replaceAll(regex,""));
    }
}
//控制台输出:123000456

猜你喜欢

转载自blog.csdn.net/xyfer1018/article/details/84236897