Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Tim Holloway wrote:You've got 2 possible strategies here. One is to use a scanner to break the text down into tokens and keep appending tokens into a StringBuilder until you reach the limit, then output the StringBuilder contents as a String. Reset the StringBuilder to empty and start appending from there. There really isn't anything more primitive that StringBuilder in Java.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Just a thought (and I having tried it), I don't think any of these solutions handle when a "word" is longer than the maximum characters per line.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Paul Clapham wrote:This sounds like something I did a long time ago. I can't track it down now, maybe it was for work but I don't think so. Anyway I used (or thought of using) a java.text.BreakIterator which sounds a lot like your requirement.
Tim Holloway wrote:Although assuming your output lines are a civilized length (60 characters or so), the English language doesn't have a lot of potential offenders and therefore syllable-backtracking isn't likely to be worth it.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:
Tim Holloway wrote:Although assuming your output lines are a civilized length (60 characters or so), the English language doesn't have a lot of potential offenders and therefore syllable-backtracking isn't likely to be worth it.
Well, I was thinking of very-long-over-hyphenated-pseudo-adjectives or a list like Democrat/Republican/Independent/Green/Pacific/Socialist/Communist, any list of words that don't have spaces between them.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
It's just a flesh wound! Or a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|