Repeat a string: Difference between revisions

 
(9 intermediate revisions by 7 users not shown)
Line 156:
even</syntaxhighlight>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="asm8080"> org 100h
jmp demo
 
; Repeat the string at DE into HL, B times
repeat: mvi c,'$' ; string terminator
xra a ; repeat 0x?
ora b
mov m,c ; then empty string
rz
rpt1: push d ; save begin of string to repeat
chcpy: ldax d ; copy character from input to output
mov m,a
inx d ; advance pointers
inx h
cmp c ; end of string?
jnz chcpy
pop d ; restore begin of string to repeat
dcx h ; move back past terminator in copy
dcr b ; done yet?
jnz rpt1 ; if not add another copy
ret
 
demo: lxi d,ha ; get string to repeat
lxi h,buf ; place to store result
mvi b,5 ; repeat 5 times
call repeat
lxi d,buf ; print result using CP/M call
mvi c,9
jmp 5
 
ha: db 'ha$' ; string to repeat
buf: ds 32 ; place to store repeated string</syntaxhighlight>
{{out}}
<pre>hahahahaha</pre>
=={{header|8th}}==
<syntaxhighlight lang="forth">"ha" 5 s:*
Line 382 ⟶ 417:
print StringRepeat$("*", 5)
end</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">100 cls
110 print stringrepeat$("rosetta",1)
120 print stringrepeat$("ha",5)
130 print stringrepeat$("*",5)
140 end
150 function stringrepeat$(s$,n)
160 cad$ = ""
170 for i = 1 to n
180 cad$ = cad$+s$
190 next i
200 stringrepeat$ = cad$
210 end function</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|Applesoft BASIC}}
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">100 CLS : rem 100 HOME for Applesoft BASIC
110 S$ = "rosetta" : N = 1
120 GOSUB 210
130 PRINT CAD$
140 S$ = "ha" : N = 5
150 GOSUB 210
160 PRINT CAD$
170 S$ = "*" : N = 5
180 GOSUB 210
190 PRINT CAD$
200 END
210 REM FUNCTION STRINGREPEAT$(S$,N)
220 CAD$ = ""
230 FOR I = 1 TO N
240 CAD$ = CAD$+S$
250 NEXT I
260 RETURN</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">100 REM Repeat a string
110 LET S$ = "rosetta"
120 LET N = 1
130 GOSUB 210
140 LET S$ = "ha"
150 LET N = 5
160 GOSUB 210
170 LET S$ = "*"
180 LET N = 5
190 GOSUB 210
200 STOP
210 REM FUNCTION StringRepeat$(S$,N)
220 FOR I = 1 TO N
230 PRINT S$;
240 NEXT I
250 PRINT
260 RETURN
270 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|QBasic}}===
Line 396 ⟶ 496:
PRINT StringRepeat$("*", 5)
END</syntaxhighlight>
 
==={{header|Quite BASIC}}===
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|GW-BASIC}}
{{works with|MSX BASIC}}
{{works with|PC-BASIC|any}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">100 CLS
110 LET S$ = "rosetta"
115 LET N = 1
120 GOSUB 210
130 PRINT C$
140 LET S$ = "ha"
145 LET N = 5
150 GOSUB 210
160 PRINT C$
170 LET S$ = "*"
175 LET N = 5
180 GOSUB 210
190 PRINT C$
200 END
210 REM FUNCTION STRINGREPEAT$(S$,N)
220 LET C$ = ""
230 FOR I = 1 TO N
240 LET C$ = C$ + S$
250 NEXT I
260 RETURN</syntaxhighlight>
 
==={{header|True BASIC}}===
Line 410 ⟶ 538:
PRINT StringRepeat$("*", 5)
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Repeat a string"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
DECLARE FUNCTION StringRepeat$ (s$, n)
 
FUNCTION Entry ()
 
PRINT StringRepeat$ ("rosetta", 1)
PRINT StringRepeat$ ("ha", 5)
PRINT StringRepeat$ ("*", 5)
 
END FUNCTION
FUNCTION StringRepeat$ (s$, n)
cad$ = ""
FOR i = 1 TO n
cad$ = cad$ + s$
NEXT i
RETURN cad$
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 830 ⟶ 982:
=={{header|E}}==
<syntaxhighlight lang="e">"ha" * 5</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
func$ rep s$ n .
for i to n
r$ &= s$
.
return r$
.
print rep "ha" 5
</syntaxhighlight>
 
=={{header|ECL}}==
Line 872 ⟶ 1,035:
 
=={{header|Elena}}==
ELENA 46.x :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 879 ⟶ 1,042:
public program()
{
var s := new Range(0, 5).selectBy::(x => "ha").summarize(new StringWriter())
}</syntaxhighlight>
 
Line 1,214 ⟶ 1,377:
say "ha" repeated 5 times;
end the story.</syntaxhighlight>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(str* "ha" 5)
</syntaxhighlight>
 
{{out}}
 
<pre>
hahahahaha
</pre>
 
=={{header|IS-BASIC}}==
Line 1,390 ⟶ 1,565:
 
=={{header|LabVIEW}}==
I don't know if there is a built-in function for this, but it is easily achieved with a For loop and Concatenate Strings.<br/>
[[file:LabVIEW_Repeat_a_string.png]]
<br/>
By using built in functions:
 
[[File:Panel.png]]
[[File:BlockDiagram.png]]
<br/>
 
=={{header|Lambdatalk}}==
Line 1,435 ⟶ 1,616:
 
=={{header|langur}}==
<syntaxhighlight lang="langur">"ha" * 5</syntaxhighlight>
This example looks like Perl, but the x operator doesn't just multiply strings in langur.
<syntaxhighlight lang="langur">"ha" x 5</syntaxhighlight>
 
=={{header|Lasso}}==
Line 2,900 ⟶ 3,080:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">System.print("ha" * 5)</syntaxhighlight>
 
{{out}}
885

edits