Limiting the number of characters in a string, and chopping off the rest

前端 未结 8 1192
故里飘歌
故里飘歌 2020-12-08 02:02

I need to create a summary table at the end of a log with some values that are obtained inside a class. The table needs to be printed in fixed-width format. I have the cod

8条回答
  •  一向
    一向 (楼主)
    2020-12-08 02:33

    You can use the Apache Commons StringUtils.substring(String str, int start, int end) static method, which is also null safe.

    See: http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringUtils.html#substring%28java.lang.String,%20int,%20int%29

    and http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/src-html/org/apache/commons/lang/StringUtils.html#line.1961

提交回复
热议问题