Repeat a string: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: indented the separater comments to not interfere with reading of the source code, added ''big sky'' comment. -- ~~~~)
Line 904: Line 904:
/*all examples are equivalent, but not created equal.*/
/*all examples are equivalent, but not created equal.*/


/*───────────────────────────────────────────*/
/*---------------------*/
y='ha'
y='ha'
z=copies(y,5)
z=copies(y,5)
/*───────────────────────────────────────────*/
/*---------------------*/
z=copies( 'ha', 5 )
z=copies( 'ha', 5 )
/*───────────────────────────────────────────*/
/*---------------------*/
y='ha'
y='ha'
z=y||y||y||y||y
z=y||y||y||y||y
/*───────────────────────────────────────────*/
/*---------------------*/
y='ha'
y='ha'
z=y || y || y || y || y
z=y || y || y || y || y /*same as previous, but the "big sky" version*/
/*───────────────────────────────────────────*/
/*---------------------*/
y='ha'
y='ha'
z=''
z=''
Line 921: Line 921:
z=z||y
z=z||y
end
end
/*───────────────────────────────────────────*/
/*---------------------*/
y="ha"
y="ha"
z=
z=
Line 927: Line 927:
z=z||y
z=z||y
end
end
/*───────────────────────────────────────────*/
/*---------------------*/
y="ha"
y="ha"
z=
z=
Line 934: Line 934:
end
end


/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=left('',5,y)
z=left('',5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=right('',5,y)
z=right('',5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=substr('',1,5,y)
z=substr('',1,5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=center('',5,y)
z=center('',5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=centre('',5,y)
z=centre('',5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=space('',5,y)
z=space('',5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=translate('@@@@@',y,"@")
z=translate('@@@@@',y,"@")
/*───────────────────────────────────────────*/
/*---------------------*/
y='abcdef'
y='abcdef'
z=five(y)
z=five(y)
Line 963: Line 963:
if length(g)>=5*length(y) then return g
if length(g)>=5*length(y) then return g
return five(y||g)
return five(y||g)
/*───────────────────────────────────────────*/
/*---------------------*/
y='something wicked this way comes.'
y='something wicked this way comes.'
z=y||y||y||y||y||y||y||y||y||y||y||y|\y||y||y
z=y||y||y||y||y||y||y||y||y||y||y||y|\y||y||y
z=left(z,5*length(y))
z=left(z,5*length(y))
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=copies('',5,y)
z=copies('',5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=lower('',1,5,y)
z=lower('',1,5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=lower('',,5,y)
z=lower('',,5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
z='+'
z='+'
z=upper('',1,5,y)
z=upper('',1,5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
z=upper('',,5,y)
z=upper('',,5,y)
/*───────────────────────────────────────────*/
/*---------------------*/

y='charter bus.'
y='charter bus.'
z='*****'
z='*****'
z=changestr('*',z,y)
z=changestr('*',z,y)
/*───────────────────────────────────────────*/
/*---------------------*/
y='what the hey!'
y='what the hey!'
z=
z=
Line 992: Line 991:
z=z||y
z=z||y
end
end
/*───────────────────────────────────────────*/
/*---------------------*/
y='what the hey!'
y='what the hey!'
z=
z=
do until length(z)==5*length(y)
do until length(z)==5*length(y)
z=insert(z,0,y)
z=insert(z,0,y)
end
end
/*───────────────────────────────────────────*/
/*---------------------*/
y='yippie ki yay'
y='yippie ki yay'
z=
z=
Line 1,004: Line 1,003:
z=overlay(y,z,i)
z=overlay(y,z,i)
end
end
/*───────────────────────────────────────────*/
/*---------------------*/
y='+'
y='+'
z=justify('',5,y)
z=justify('',5,y)
/*───────────────────────────────────────────*/
/*---------------------*/
whatever_this_variable_is_____it_aint_referenced_directly= 'boy oh boy.'
whatever_this_variable_is_____it_aint_referenced_directly= 'boy oh boy.'
z=; signal me; me:
z=; signal me; me:
Line 1,013: Line 1,012:
z=z||strip(subword(sourceline(sigl-1),2),,"'")
z=z||strip(subword(sourceline(sigl-1),2),,"'")
end
end
/*───────────────────────────────────────────*/
/*---------------------*/
y="any more examples and the angry townfolk will burn the castle."
y="any more examples & the angry townfolk with pitchforks will burn the castle."
parse value y||y||y||y||y with z
parse value y||y||y||y||y with z


exit
exit
/*═══════════════════════════CHANGESTR subroutine═══════════════════════*/
/*───────────────────────────CHANGESTR subroutine───────────────────────*/
changestr: procedure; parse arg o,h,n; r=; w=length(o); if w==0 then return n||h
changestr: procedure; parse arg o,h,n,,r; w=length(o); if w==0 then return n||h
do forever; parse var h y (o) _ +(w) h; if _=='' then return r||y; r=r||y||n; end</lang>
do forever; parse var h y (o) _ +(w) h; if _=='' then return r||y; r=r||y||n; end</lang>