a = a + "Yeah, I formulated that poorly. Sorry, it was late. But" + chr(10)
a = a + "sometimes I just has a bunch of lines which I want" + chr(10)
a = a + "to put on the screen in that exact order." + chr(10)
a = a + "I just wondered what would be most effective here" + chr(10)
Still, the automatizing linebreak stuff is much more interesting. Loads of great hacks here!
At my current project I go for monospace font, so I can just count the number of words:
function output_linebreaker (old$ as string, lineLength as integer)
new$ as string = ""
cutSpace as integer rem Stores the space where we cut the string
while len(old$) > 0
rem TRANSFER A CHUNK TO new$
if FindString( old$, chr(10), 1, 1 ) = 0 rem IF NO LINE BREAK IS FOUND
if len(old$) < lineLength
new$ = new$ + old$
old$ = ""
else
cutSpace = findstringreverse (old$, " ", 1, lineLength) rem Find the space where we cut
if cutSpace = 0 then cutSpace = 50 rem if no space found, cut at random place
new$ = new$ + left(old$, cutSpace) + chr(10) rem Copy to new$ (No space)
old$ = right(old$, len(old$)-cutSpace) rem Crop old
endif
else rem IF LINEBREAK IS FOUND
if FindString( old$, chr(10), 1, 1 ) > lineLength rem If the first line is too long and need to be broken -- just cut the first [] characters, (find space using findstringreverse)
cutSpace = findstringreverse (old$, " ", 1, lineLength) rem Find the space where we cut
if cutSpace = 0 then cutSpace = 50 rem if no space found, cut at random place
new$ = new$ + left(old$, cutSpace-1) + chr(10) rem Copy to new$ (PROBLEM? did I solve this?)
old$ = right(old$, len(old$)-cutSpace) rem Crop old
else rem IF THE FIRST LINE IS SHORT ENOUGH ON ITS OWN
if FindString(old$, chr(10), 1, 1) = 1 rem if the line break is the first char
new$ = new$ + chr(10)
old$ = right(old$, len(old$)-1)
else
new$ = new$ + left(old$, FindString(old$, chr(10))-1) + chr(10)
old$ = right(old$, len(old$)-FindString(old$, chr(10)))
endif
endif
endif
endwhile
endfunction new$