[Solved] Get count leading zeros in a string


You could play with parsing back and forward the string into a number, for example Integer.parseInt() will ignore leading zeros

    final String xs = "0001254200";
    int i = xs.length() - String.valueOf(Integer.parseInt(xs)).length();
    System.out.println(i);

    //Another option based on Titus comment

    i = xs.length() - xs.replaceAll("^0+", "").length();
    System.out.println(i);

0

solved Get count leading zeros in a string