Repeat a string: Difference between revisions

m (Update Lang example: Fix spelling of Lang)
Line 1,542:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">(*StringRepeat["ha", solution 1 *)5]</syntaxhighlight>
rep[n_Integer,s_String]:=Apply[StringJoin,ConstantArray[s,{n}]]
(* solution 2 -- @@ is the infix form of Apply[] *)
rep[n_Integer,s_String]:=StringJoin@@Table[s,{n}]
(* solution 3 -- demonstrating another of the large number of looping constructs available *)
rep[n_Integer,s_String]:=Nest[StringJoin[s, #] &,s,n-1]</syntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
1,934

edits