Word wrap: Difference between revisions

Content added Content deleted
m (→‎version 1: used a shortcut for the 1st word. -- ~~~~)
(add PL/I derived from REXX Version 2)
Line 1,383: Line 1,383:
-> "The quick^Jbrown fox^Jjumps over^Jthe lazy dog"</lang>
-> "The quick^Jbrown fox^Jjumps over^Jthe lazy dog"</lang>


=={{header|Python}}==
=={{header|PL/I}}==
<lang pli>*process source attributes xref or(!);
ww: proc Options(main);
/*********************************************************************
* 21.08-2013 Walter Pachl derived from REXX version 2
*********************************************************************/
Dcl in record input;
Dcl out record output;
On Endfile(in) z=' ';
Dcl z char(32767) Var;
Dcl s char(32767) Var Init('');
dcl o Char(200) Var;
Dcl (i,w,p) Bin Fixed(31) Init(0);
w=72;
Read File(in) Into(z);
s=z;
Do Until(s='');
Do i=w+1 to 1 by -1;
If substr(s,i,1)='' Then Leave;
End;
If i=0 Then
p=index(s,' ');
Else
p=i;
o=left(s,p);
Write file(out) From(o);
s=substr(s,p+1);
If length(s)<200 Then Do;
Read File(in) Into(z);
s=s!!z;
End;
End;
End;</lang>
Test result using this:
<pre>
/* REXX */
Call time 'R'
'set dd:in=h:\long2.txt,recsize(30000)' /* 1000036 characters with random length words */
'set dd:out=h:\longp.72,recsize(300)'
'ww'
Say time('E')
</pre>
Output:
<pre>
A nnnnnnnnnnnnnn ooooooooooooooo nnnnnnnnnnnnnn
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
iiiiiiiii LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
etc.
</pre>

={{header|Python}}==
<pre>>>> import textwrap
<pre>>>> import textwrap
>>> help(textwrap.fill)
>>> help(textwrap.fill)