Word wrap: Difference between revisions

2,018 bytes added ,  12 years ago
GP
(GP)
Line 76:
plaything.
</pre>
 
=={{header|PARI/GP}}==
<lang parigp>wrap(s,len)={
my(t="",cur);
s=Vec(s);
for(i=1,#s,
if(s[i]==" ",
if(cur>#t,
print1(" "t);
cur-=#t+1
,
print1("\n"t);
cur=len-#t
);
t=""
,
t=concat(t,s[i])
)
);
if(cur>#t,
print1(" "t)
,
print1("\n"t)
)
};
King="And so let freedom ring from the prodigious hilltops of New Hampshire; let freedom ring from the mighty mountains of New York; let freedom ring from the heightening Alleghenies of Pennsylvania; let freedom ring from the snow-capped Rockies of Colorado; let freedom ring from the curvaceous slopes of California. But not only that: let freedom ring from Stone Mountain of Georgia; let freedom ring from Lookout Mountain of Tennessee; let freedom ring from every hill and molehill of Mississippi. From every mountainside, let freedom ring.";
wrap(King, 75)
wrap(King, 50)</lang>
 
Output:
<pre>
And so let freedom ring from the prodigious hilltops of New Hampshire; let
freedom ring from the mighty mountains of New York; let freedom ring from
the heightening Alleghenies of Pennsylvania; let freedom ring from the
snow-capped Rockies of Colorado; let freedom ring from the curvaceous
slopes of California. But not only that: let freedom ring from Stone
Mountain of Georgia; let freedom ring from Lookout Mountain of Tennessee;
let freedom ring from every hill and molehill of Mississippi. From every
mountainside, let freedom ring.
 
And so let freedom ring from the prodigious
hilltops of New Hampshire; let freedom ring from
the mighty mountains of New York; let freedom ring
from the heightening Alleghenies of Pennsylvania;
let freedom ring from the snow-capped Rockies of
Colorado; let freedom ring from the curvaceous
slopes of California. But not only that: let
freedom ring from Stone Mountain of Georgia; let
freedom ring from Lookout Mountain of Tennessee;
let freedom ring from every hill and molehill of
Mississippi. From every mountainside, let freedom
ring.</pre>
 
=={{header|Run BASIC}}==