I'm looking for a component that can take a string of arbitrary length and chop it up into "pages" for display on a 4x20 (4 lines, 20 chars per line) LCD. I'd like to add some smarts to the formatting, such that it will try to not break words at the end of the display (except for very long words), not start a new line with a space char, and not start the first letter of a word at the end of a line. If a word must be broken across lines, a hypen should be inserted prior to the break. I have started writing an implementation but if there's something out there already I'd just rather use that. Thanks
A:
Sounds like your needs are so specific (since you want hyphenation) that you will most likely not be satisfied with a generic solution.
I would suggest splitting your text in words and add those individually to a line, splitting on hyphens if necessary, and then move to the next line when full. If you work with fragments larger than a single word, your code will most likely end up very messy.
I believe the method to do this will fit on a single page. I can strongly recommend using test driven development to write such a library method.
Thorbjørn Ravn Andersen
2009-07-26 18:23:46