Generate fixed length Strings filled with whitespaces

后端 未结 13 932
借酒劲吻你
借酒劲吻你 2020-12-04 13:52

I need to produce fixed length string to generate a character position based file. The missing characters must be filled with space character.

As an example, the fi

13条回答
  •  有刺的猬
    2020-12-04 14:32

    You can also write a simple method like below

    public static String padString(String str, int leng) {
            for (int i = str.length(); i <= leng; i++)
                str += " ";
            return str;
        }
    

提交回复
热议问题