Java with leading zeros removed string

Given a string of numbers, which removes the leading zeros.

public class Test {
    public static void main(String[] args) {
        String str = "00000123569";
        System.out.println(removeZero(str)); // 123569
        str = "000012356090";
        System.out.println(removeZero(str)); // 12356090
    }

    public static String removeZero(String str) {
        int len = str.length(), i = 0;
        while (i < len && str.charAt(i) == '0') {
            i++;
        }
        return str.substring(i);
    }
}

Guess you like

Origin www.cnblogs.com/hglibin/p/11291716.html