Generate fixed length Strings filled with whitespaces

后端 未结 13 1015
借酒劲吻你
借酒劲吻你 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:39

    public static String padString(String word, int length) {
        String newWord = word;
        for(int count = word.length(); count < length; count++) {
            newWord = " " + newWord;
        }
        return newWord;
    }
    

提交回复
热议问题