Python标准库附带了模块textwrap
,提供简单的文本包装功能。Java标准库中是否有类似的东西?
在Python中,它大致是这样的:
>>> t = "a really really long string with lots of characters"
>>> import textwrap
>>> textwrap.wrap(t, 20)
[ a really really long , string with lots of , characters ]
Python标准库附带了模块textwrap
,提供简单的文本包装功能。Java标准库中是否有类似的东西?
在Python中,它大致是这样的:
>>> t = "a really really long string with lots of characters"
>>> import textwrap
>>> textwrap.wrap(t, 20)
[ a really really long , string with lots of , characters ]
标准Java库中没有,但在Apache Commons中有:
WordUtils.wrap:转化为中国语言为WordUtils.wrap。