break long string into print lines

I know I can do this in a real brute force way but is there an easy/elegant way.

I start with a text field with several paragraphs of text. I save it to a TEXT field in a SQLite database and then in another program read it in and need to print it on a report (using BK_Shorts). How is the best way to break the string down to print line lengths while not breaking the middle of a word?

I know I can break it down into an array of individual words then build a string by adding words until it reaches a certain length but this seems kinda klutzy. Any suggestions?


If you have RegExRX, I’m pretty sure I have a sample pattern for that. I’d post it but I’m without a computer for a few days.

If you don’t, perhaps someone else can?

First off define “print line length”… is it a line that does not exceed X number of characters?
or it is a line that does not exceed X number of print units (pixels/points whatever)?

Because remember that unless you are using a mono-spaced font like Courier, Menlo to name a few… lines of the same number of characters will NOT be the same “length”


each of those is 5 “characters”, but vastly different lengths

and even if you ARE using a mono-spaced font… if the user changes the font SIZE (assuming they can)… then that will mess it up as well. The best approach is to let the report application flow the text for you


You’re not kidding.

How exactly are you using the field in Shorts?

In a code-built report, BKS_Shorts.TextItem has a WrapLines boolean that should automatically calculate how to draw the lines wrapped (by word) to fit the width of the object. Similarly, in the Report Designer there is a WrapLines checkbox under the Behavior section.

Tim I am using Code built report, I was unaware of the wraplines boolean. I think that will make it work. thanks

you should ask for a xojo ide on an iphone …

Tim - the WrapLines works great except for 1 problem. After that data has printed, since I don’t know in advance how much text there is, I don’t know where the text stopped printing so that I can start printing the next section…

what i do is to establish max_text_lenght. i use mid() to know if in the position of max_text_lenght is an empty character. if no i advance one character (using mid) and again check if is empty. if is empty i add one to the current position and again using mid i take the string using mid from that position. it works perfect