Here you can find the source of leftPad(String srcString, char c, int length)
public static String leftPad(String srcString, char c, int length)
//package com.java2s; //License from project: LGPL public class Main { public static String leftPad(String srcString, char c, int length) { if (srcString == null) { srcString = ""; }//from www . ja va 2 s .c o m int tLen = srcString.length(); if (tLen >= length) return srcString; int iMax = length - tLen; StringBuilder sb = new StringBuilder(); for (int i = 0; i < iMax; i++) { sb.append(c); } sb.append(srcString); return sb.toString(); } public static int length(String str) { if (str == null) return 0; char[] c = str.toCharArray(); int len = 0; for (int i = 0; i < c.length; i++) { len++; if (!isLetter(c[i])) { len++; } } return len; } private static boolean isLetter(char charStr) { int k = 0x80; return charStr / k == 0 ? true : false; } }