troubleshooting Question

Splitting a long string in java

Avatar of Greengiants15
Greengiants15 asked on
Java
13 Comments2 Solutions549 ViewsLast Modified:
Hello Experts,

I need to split a VERY long string in Java at every 132 characters.  But here's the trick:  I need to split the String at the last instance of a whitespace of the 132 characters.  So it's possible that the new String may be less than 132 characters.  You see, if I have a long sentence and the 132nd character is in the middle of a word, then I don't want to chop that word.  Rather I'd like to capture the whole word.  I can't go over 132 characters, but I can go under:
Ex:
String x = "..... impossible to realize."
Let's say the 132nd character is after the 't' in the word "to".  Now I don't want to split the 't' and 'o'.  I'd rather stop after the workd "impossible" and begin the next line with "to".

Any expert out there than can help?
ASKER CERTIFIED SOLUTION
Greengiants15

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros