Convert a String to Padded Fixed Length
Return a String padded to a fixed length using a specified padding character.
Javadoc available at https://www.javatapas.com/docs/javatapas/string/FixedLengthPadding.html
public static String fixedLengthPadding(String inStr, int fixedInt) {
return fixedLengthPadding(inStr, fixedInt, ' ', true);
}
public static String fixedLengthPadding(String inStr, int fixedInt, char pad, boolean rightLeft) {
int blanks = fixedInt - inStr.length();
StringBuffer outStrBuf = new StringBuffer(inStr);
if (blanks >= 0) { // start if
for(int i = 0; i < blanks; i++){ //start for
if(rightLeft){outStrBuf.insert(0,pad);}
else{outStrBuf.append(pad);}
} // end for
} // end if
else {outStrBuf = outStrBuf.delete(fixedInt,inStr.length());}
return outStrBuf.toString();
}