Java String Pad Zero zeroPad(String encodeString, int padding)

Here you can find the source of zeroPad(String encodeString, int padding)

Description

zero Pad

License

Apache License

Declaration

public static String zeroPad(String encodeString, int padding) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String zeroPad(String encodeString, int padding) {
        try {//from  w  ww  .  ja  v a 2  s.c  o  m
            int v = Integer.parseInt(encodeString);
            String pad = String.valueOf(v);
            while (pad.length() < padding) {
                pad = "0" + pad;
            }
            return pad;
        } catch (Exception e) {
            return encodeString;
        }
    }
}

Related

  1. zeroPad(final String s, final int fieldLength)
  2. zeroPad(String encodeString, int padding)
  3. zeropad(String number, int size)
  4. zeroPad(String s, int fieldLength)
  5. zeropad(String s, int i)