Comma quibbling: Difference between revisions
Content deleted Content added
No edit summary |
Walterpachl (talk | contribs) PL/I added |
||
Line 117:
Input: ['ABC', 'DEF', 'G', 'H'] -> Output: '{ABC, DEF, G and H}'
>>> </lang>
=={{header|PL/I}}==
<lang pli>*process or(!);
quib: Proc Options(main);
/*********************************************************************
* 06.10.2013 Walter Pachl
*********************************************************************/
put Edit(quibbling(''))(Skip,a);
put Edit(quibbling('ABC'))(Skip,a);
put Edit(quibbling('ABC DEF'))(Skip,a);
put Edit(quibbling('ABC DEF G H'))(Skip,a);
return;
quibbling: proc(s) Returns(Char(100) Var);
Dcl s Char(*);
Dcl result Char(100) Var;
Dcl (wi,p) Bin Fixed(31);
If s='' Then result='';
Else Do;
Do wi=1 By 1 While(s^='');
p=index(s,' ');
If p=0 Then Do;
If wi>1 Then
result=result!!' and '!!s;
else
result=s;
s='';
End;
Else Do;
If wi=1 Then
result=left(s,p-1);
Else
result=result!!', '!!left(s,p-1);
s=substr(s,p+1);
End;
End;
End;
Return('{'!!result!!'}');
End;
End;</lang>
{{out}}
<pre>
{}
{ABC}
{ABC, DEF}
{ABC, DEF, G, H}
</pre>
=={{header|Rexx}}==
|