Word wrap: Difference between revisions
Content added Content deleted
(Added Commodore BASIC) |
|||
Line 1,041: | Line 1,041: | ||
threw it up on high and caught it, and this ball was her favorite |
threw it up on high and caught it, and this ball was her favorite |
||
plaything.</pre> |
plaything.</pre> |
||
=={{header|Commodore BASIC}}== |
|||
Nothing terribly fancy. Except for screen control codes, this should actually work on a wide variety of 8-bit BASIC outside of the Commodore realm. Note that strings are limited to 255 total characters, and <code>INPUT</code> will retrieve only a limited number of characters (less than 80 on the Commodore 64) even for a string, not to mention that special characters such as comma, semicolon, etc. have special meaning and are not captured. |
|||
<lang gwbasic>10 rem word wrap - commodore basic |
|||
20 rem rosetta code |
|||
30 s$="":co=40:gosub 200 |
|||
35 print chr$(147);chr$(14) |
|||
40 print "The current string is:" |
|||
41 print chr$(18);s$;chr$(146) |
|||
42 print:print "Enter a string, blank to keep previous," |
|||
43 print "or type 'sample' to use a preset"len(z$)" character string." |
|||
44 print:input s$:if s$="sample" then s$=z$ |
|||
45 print:print "enter column limit, 10-80 [";co;"{left}]";:input co |
|||
46 if co<12 or co>80 then goto 45 |
|||
50 print chr$(147);"Wrapping on column";co;"results as:" |
|||
55 gosub 400 |
|||
60 print |
|||
65 print r$ |
|||
70 print |
|||
80 input "Again (y/n)";yn$ |
|||
90 if yn$="y" then goto 35 |
|||
100 end |
|||
200 rem set up sample string |
|||
205 z$="Lorem Ipsum is simply dummy text of the printing and typesetting " |
|||
210 z$=z$+"industry. Lorem Ipsum has been the industry's standard dummy " |
|||
215 z$=z$+"text ever since the 1500s, when an unknown printer took a galley " |
|||
220 z$=z$+"of type and scrambled it to make a type specimen book." |
|||
225 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$<>" " then next i |
|||
430 as$=as$+left$(tp$,co-1-i)+chr$(13):tp$=mid$(tp$,co-i+1,len(tp$)):i=0 |
|||
435 goto 405 |
|||
440 as$=as$+tp$ |
|||
450 r$=as$ |
|||
460 return</lang> |
|||
{{out}} |
|||
<pre>Wrapping on column 40 results as: |
|||
Lorem Ipsum is simply dummy text of the |
|||
printing and typesetting industry. |
|||
Lorem Ipsum has been the industry's |
|||
standard dummy text ever since the |
|||
1500s, when an unknown printer took a |
|||
galley of type and scrambled it to make |
|||
a type specimen book. |
|||
Again (y/n)? y |
|||
... |
|||
Wrapping on column 20 results as: |
|||
Lorem Ipsum is |
|||
simply dummy text |
|||
of the printing and |
|||
typesetting |
|||
industry. Lorem |
|||
Ipsum has been the |
|||
industry's standard |
|||
dummy text ever |
|||
since the 1500s, |
|||
when an unknown |
|||
printer took a |
|||
galley of type and |
|||
scrambled it to |
|||
make a type |
|||
specimen book. |
|||
Again (y/n)? n |
|||
ready. |
|||
█</pre> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |