Repeat a string: Difference between revisions

Content added Content deleted
(add repeating single characters)
Line 1: Line 1:
{{task|String manipulation}}Take a string and repeat it some number of times. Example: repeat("ha", 5) => "hahahahaha"
{{task|String manipulation}}Take a string and repeat it some number of times. Example: repeat("ha", 5) => "hahahahaha"

If there is a simpler/more efficient way to repeat a single “character”, show that as well (i.e. repeat-char("*", 5) => "*****").


=={{header|Ada}}==
=={{header|Ada}}==
Line 67: Line 69:


(princ (repeat-string 5 "hi"))</lang>
(princ (repeat-string 5 "hi"))</lang>

A single character may be repeated using just the builtin <code>make-string</code>:
<lang lisp>(make-string 5 :initial-element #\X)</lang>
produces “XXXXX”.


=={{header|D}}==
=={{header|D}}==