List of utility methods to do String Pad Left
StringBuilder | leftPad(StringBuilder pStringBuilder, int pLength, char pChar) Similar to the Oracle lpad command. StringBuilder lTempBuffer = new StringBuilder(pLength); while ((lTempBuffer.length() + pStringBuilder.length()) < pLength) { lTempBuffer.append(pChar); lTempBuffer.append(pStringBuilder); return lTempBuffer; |
byte[] | leftPadByteArray(byte[] source, int size) Left pad byte array to a byte array with given size. byte[] bs = new byte[size]; if (size < source.length) { return null; int startPos = size - source.length; System.arraycopy(source, 0, bs, startPos, source.length); return bs; |
String | leftPadded(String src, int len) Pad the src to make it [len] bytes with trailing spaces. return leftPadded(src, len, ' '); |
String | leftPaddedString(String string, int length, char paddingChar) left Padded String if (string.length() > length) { System.err.println("WARNING: String to pad is longer than expected length. Return original string."); return string; if (string.length() == length) return string; return String.format("%0" + (length - string.length()) + "d", 0).replace('0', paddingChar).concat(string); |
StringBuffer | leftPadding(final StringBuffer strBuf, final int bufLen, final char fill) Left Pad Stringbuffer with special char while (strBuf.length() < bufLen) strBuf.insert(0, fill); return strBuf; |
String | leftPadding(String in, int count, char pad) Applies a left padding to the provided string. if (in.length() >= count) return in; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count - in.length(); i++) { sb.append(pad); for (char c : in.toCharArray()) { sb.append(c); ... |
String | leftPadding(String orgStr, String addStr, int strLength) left Padding if (orgStr.length() < strLength) { String padding = new String(); int len = strLength - orgStr.length(); for (int loop = 0; loop < len; loop++) { padding = padding + addStr; padding = padding + orgStr; return padding; ... |
String | leftPadInt(int number, int width) Left pads number with zero's return leftPad(Integer.toString(number), width, '0'); |
String | leftPadMultiline(String input, char padChar, int padWidth) left Pad Multiline StringBuilder buf = new StringBuilder(input); String paddingString = repeatedChar(padChar, padWidth); int i = 0; while (i < buf.length()) { if (buf.charAt(i) == '\n') { buf.insert(i + 1, paddingString); i++; ... |
String | leftPadString(String str, char pad, int length) left Pad String if (str.length() >= length) return str; StringBuffer sb = new StringBuffer(); while (sb.length() < length - str.length()) sb.append(pad); sb.append(str); return sb.toString(); |