I need as the title says to wrap a text (a String) in Java in both, automatic and manual mode. For automatic mode I use the "word-wrap" library that wrap the text with a max-length characters, but I need also to add a manual mode, like for example with the key "/". Can someone help me please?
I have tried to have a String like "this is an example string/I need to wrap" and also if I use a for loop to split the strings the word wrap, that is executed before. This is an example:
That is an example I need to fix /a example test.
Say the manual wrap key is "/" and the max characters are 35. The result will be:
That is an example I need to fix
a example test.
But here how is it:
That is an example I need to fix
a
example test
Here's a method that demonstrates what you want.
And using it like so
You should get
Alternatively your could use the ApacheCommon's
WordUtils#wrapmethod