Repeat a string: Difference between revisions

→‎{{header|Swift}}: Added the builtin way and a handy function.
(→‎{{header|Swift}}: Added the builtin way and a handy function.)
Line 2,183:
 
=={{header|Swift}}==
 
=== The Builtin Way ===
 
<lang swift>print(String(repeating:"*", count: 5))</lang>
{{out}}*****
 
=== Functions ===
 
<lang swift>func * (left:String, right:Int) -> String {
return String(repeating:left, count:right)
}
 
print ("HA" * 5)
</lang>
{{out}}
HAHAHAHAHA
 
 
=== Extensions ===
Using extensions to do the repetition which makes for an easier syntax when repeating Strings, and using String.extend() to get faster evaluation.
 
Anonymous user