Anonymous user
Repeat a string: Difference between revisions
→{{header|Smalltalk}}
(→{{header|REXX}}: included a CHANGESTR subroutine (function) as a link. -- ~~~~) |
|||
Line 1,109:
{{works with|Pharo|1.4}}
{{works with|Smalltalk/X}}
By creating a collection of 5 'ha', and joining them to a string:
<lang smalltalk>((1 to: 5) collect: [:x | 'ha']) joinUsing: ''.</lang>
or:{{works with|Smalltalk/X}}
<lang smalltalk>(Array new:5 withAll:'ha') asStringWith:''.</lang>
By creating a WriteStream, and putting 5 times the string 'ha' into it:
Line 1,119 ⟶ 1,121:
5 timesRepeat: [ws nextPutAll: 'ha'].
ws contents.</lang>
alternatively:
<lang smalltalk>(String streamContents:[:ws | 5 timesRepeat: [ws nextPutAll: 'ha']])</lang>
Evaluates to:
|