Word wrap: Difference between revisions

Commodore BASIC - Decided to use sample text from Wikipedia, and improved the initialization of the sample string. Added support for hyphenated words to be broken during wrap.
(Added Commodore BASIC)
(Commodore BASIC - Decided to use sample text from Wikipedia, and improved the initialization of the sample string. Added support for hyphenated words to be broken during wrap.)
Line 1,066:
100 end
200 rem set up sample string
205 z$=data "Lorem Ipsum is simplytypically dummya textcorrupted ofversion the printingof and'De typesettingfinibus "
210 data "bonorum et malorum', a first-century BC text by the Roman statesman "
210 z$=z$+"industry. Lorem Ipsum has been the industry's standard dummy "
215 data "and philosopher Cicero, with words altered, added, and removed to "
215 z$=z$+"text ever since the 1500s, when an unknown printer took a galley "
220 data "make it nonsensical, improper Latin."
220 z$=z$+"of type and scrambled it to make a type specimen book."
225 returndata "zzz"
230 z$=""
235 read tp$:if tp$<>"zzz" then z$=z$+tp$:goto 235
240 return
400 rem word-wrap string
401 tp$=s$:as$=""
405 if len(tp$)<=co then goto 440
410 for i=0 to co-1:c$=mid$(tp$,co-i,1)
420 if c$<>" " and c$<>"-" then next i
430425 asad$=as$+left$(tp$,co-1-i)+chr$(13):tpif c$=mid"-" then ad$(tp$,co="-i"+1,lenchr$(tp$13)):i=0
430 as$=as$+left$(tp$,co-1-i)+ad$:tp$=mid$(tp$,co-i+1,len(tp$)):i=0
435 goto 405
440 as$=as$+tp$
Line 1,085 ⟶ 1,089:
 
<pre>Wrapping on column 40 results as:
Lorem Ipsum is simplytypically dummya corrupted text of the
version of 'De finibus bonorum et
printing and typesetting industry.
malorum', a first-century BC text by
Lorem Ipsum has been the industry's
the Roman statesman and philosopher
standard dummy text ever since the
Cicero, with words altered, added, and
1500s, when an unknown printer took a
removed to make it nonsensical,
galley of type and scrambled it to make
aimproper Latin. type specimen book.
Again (y/n)? y
 
 
Line 1,101 ⟶ 1,105:
 
Wrapping on column 20 results as:
Lorem Ipsum is
simplytypically a dummy text
ofcorrupted theversion printing and
typesetting of 'De finibus
industry.bonorum et Lorem
Ipsummalorum', hasa been thefirst-
industry'scentury BC text by standard
dummy text ever the Roman statesman
sinceand thephilosopher 1500s,
when an unknown Cicero, with words
printer took a altered, added, and
galleyremoved ofto typemake andit
scramblednonsensical, it to
make a type improper Latin.
specimen book.
Again (y/n)? n
 
ready.
113

edits