- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
// gotta love this hack
final private static String PADDING =
" ";
private static String stringFormat(String stringToFormat, int fieldSize, boolean rightJustify) {
// and Java doesn't really excel at this kind of thing either
if (stringToFormat.length() >= fieldSize) {
return stringToFormat.substring(0, fieldSize);
} else {
return rightJustify ?
PADDING.substring(0, fieldSize - stringToFormat.length()) + stringToFormat:
stringToFormat + PADDING.substring(0, fieldSize - stringToFormat.length());
}
}