Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to split a string into multiple lines of x characters

807601Dec 14 2007 — edited Dec 17 2007
Hi

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.

Example:

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
lazy dog

How can I achieve this in java?

Thanks
J
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 14 2008
Added on Dec 14 2007
26 comments
3,457 views