Originally posted by Bruce Lee:
Hi all how do I insert a newline at every 10 character with the condition it must be a space.
Hi all, this is bruce lee. I'm still a novice in Java. Pls help in whatever you can.
Anyone can help?
One idea would be to convert your String to something mutable like StringBuffer or StringBuilder, and then use a simple loop to insert the newlines. Then convert it to a String.
That's a very high level sketch ... there are quite a few little details left out ... finding all the words, spaces between words, two spaces after a period, a single word that is longer than line max and so on. Does it seem to be the right direction?