How to split a string into multiple lines of x characters each
I want to split a string into multiple lines of 'x' characters without breaking a word. That is, for example, if x = 13, if the 13th character falls in the middle of a word, this word should not be considered for the first line, but must go into the next line.
If the string is "The quick fox jumped over a lazy dog", and I want to break this into multiple line of 13 characters, it should be like this:
The quick fox
jumped over a
How can I achieve this in java?