Here you can find the source of fillString(String formatString, int length, char fillChar, boolean leftFillFlag)
Parameter | Description |
---|---|
The | string to be format. |
public static String fillString(String formatString, int length, char fillChar, boolean leftFillFlag)
//package com.java2s; public class Main { /**// w ww . ja v a2s.co m * Method fill string * * @param The string to be format. * */ public static String fillString(String formatString, int length, char fillChar, boolean leftFillFlag) { if (null == formatString) { formatString = ""; } int strLen = formatString.length(); if (strLen >= length) { if (true == leftFillFlag) // left fill return formatString.substring(strLen - length, strLen); else return formatString.substring(0, length); } else { StringBuffer sbuf = new StringBuffer(); int fillLen = length - formatString.length(); for (int i = 0; i < fillLen; i++) { sbuf.append(fillChar); } if (true == leftFillFlag) // left fill { sbuf.append(formatString); } else { sbuf.insert(0, formatString); } String returnString = sbuf.toString(); sbuf = null; return returnString; } } /** * Method convert byte[] to String * * @param The string to be format. * */ public static String toString(byte[] buffer) { if (null == buffer) return null; else return new String(buffer); } }