Repeat a string: Difference between revisions

(Add Processing)
Line 48:
 
In Flex, there is the method [http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/StringUtil.html#repeat%28%29 mx.utils.StringUtil.repeat()].
 
===Iterative version===
<lang ActionScript>function repeatString(string:String, numTimes:uint):String
Line 56 ⟶ 57:
return output;
}</lang>
 
===Recursive version===
The following double-and-add method is much faster when repeating a string many times.
Line 65 ⟶ 67:
return tmp + tmp;
}</lang>
 
===Flex===
<lang ActionScript>import mx.utils.StringUtil;
Line 334 ⟶ 337:
 
=={{header|Burlesque}}==
 
<lang burlesque>
blsq ) 'h5?*
Line 531 ⟶ 533:
writeln(chars);
}</lang>
 
=={{header|DCL}}==
Not exactly what the task asks for but at least it is something;
Line 577 ⟶ 580:
 
=={{header|Déjà Vu}}==
 
<lang dejavu>!. concat( rep 5 "ha" )</lang>
{{out}}
Line 793 ⟶ 795:
*****
</pre>
 
=={{header|Free Pascal}}==
<lang pascal>strUtils.dupeString('ha', 5)</lang>
Repetition of a single character:
<lang pascal>stringOfChar('*', 5)</lang>
If the repeated character happens to be the space character:
<lang pascal>space(5)</lang>
 
=={{header|Frink}}==
Line 986 ⟶ 995:
<lang javascript>
console.log("ha".repeat(5)); // hahahahaha</lang>
 
====Repetition by Egyptian multiplication====
For larger numbers of repetitions, however, it proves significantly faster to progressively double a copy of the original string (concatenating it with itself). Intermediate stages of doubling are appended to an accumulator wherever required for binary composition of the target number.
Line 1,326 ⟶ 1,336:
}
}</lang>
 
 
 
=={{header|NetRexx}}==
Line 1,434 ⟶ 1,442:
 
=={{header|Oforth}}==
 
<lang Oforth>StringBuffer new "abcd" <<n(5)</lang>
 
Line 1,477 ⟶ 1,484:
 
=={{header|PARI/GP}}==
 
===Version #1. Based on recursion.===
This solution is recursive and unimaginably bad. Slightly less bad versions can be designed, but that's not the point: don't use GP for text processing if you can avoid it. If you really need to, it's easy to create an efficient function in PARI (see [[#C|C]]) and pass that to GP.
Line 1,540 ⟶ 1,546:
 
=={{header|Pascal}}==
See [[#Delphi|Delphi]] or [[#Free Pascal|Free Pascal]], as standard Pascal does not know strings of unlimited length.
See [[Repeat_a_string#Delphi | Delphi]]
 
=={{header|Perl}}==
Line 1,675 ⟶ 1,681:
 
=={{header|Racket}}==
 
<lang racket>
#lang racket
Line 1,891 ⟶ 1,896:
 
=={{header|Scratch}}==
 
This example requires making variables named "String", "Count", and "Repeated" first.
 
Line 2,337 ⟶ 2,341:
defer allocator.free(ex);
}</lang>
 
=={{header|zkl}}==
Same as [[#Ruby|Ruby]]
<lang zkl>"ha" * 5 # --> "hahahahaha"</lang>
 
149

edits