Java Utililty Methods String Align Center

List of utility methods to do String Align Center

Description

The list of methods to do String Align Center are organized into topic(s).

Method

StringalignCenter(String sLine, int iSize)
align Center
if (sLine.length() > iSize) {
    return alignRight(sLine.substring(0, (sLine.length() + iSize) / 2), iSize);
} else {
    return alignRight(sLine + getWhiteString((iSize - sLine.length()) / 2), iSize);
StringalignCenter(String str, int length)
align Center
return alignCenter(str, length, false);
StringalignCenter(String substring, int totalWidth, char fill)
Returns a string of the specified length where the substring is located in the middle, padded with a character on both sides.
if (substring.length() > totalWidth) {
    return substring.substring(0, totalWidth);
} else {
    final double padding = (totalWidth - substring.length()) / 2d;
    final int left = (int) Math.floor(padding);
    final int right = (int) Math.ceil(padding);
    return repeat("" + fill, left) + substring + repeat("" + fill, right);