Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Repeat_a_string
note: String manipulation

View file

@ -0,0 +1,10 @@
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” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
{{Template:Strings}}
<br><br>

View file

@ -0,0 +1 @@
print(ha * 5)

View file

@ -0,0 +1,43 @@
* Repeat a string - 19/04/2020
REPEATS CSECT
USING REPEATS,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
SAVE (14,12) save previous context
ST R13,4(R15) link backward
ST R15,8(R13) link forward
LR R13,R15 set addressability
XPRNT C24,24 print c24
LA R1,PARMLST pg=repeat(cx,ii) - repeat('abc ',6)
BAL R14,REPEAT call repeat
XPRNT PG,L'PG print pg
L R13,4(0,R13) restore previous savearea pointer
RETURN (14,12),RC=0 restore registers from calling save
REPEAT CNOP 0,4 procedure repeat(b,a,i)
STM R2,R8,REPEATSA save registers
L R2,0(R1) @b=%r1
L R3,4(R1) @a=%(r1+4)
L R4,8(R1) @i=%(r1+8)
LR R5,R3 length(a) before a
SH R5,=H'2' @lengh(a)
LH R6,0(R5) l=length(a)
LR R7,R6 l
BCTR R7,0 l-1
L R8,0(R4) i=%r4
LTR R8,R8 if i<=0
BNP RET then return
LOOP EX R7,MVCX move a to b len R6
AR R2,R6 @b+=l
BCT R8,LOOP loop i times
RET LM R2,R8,REPEATSA restore registers
BR R14 return
PARMLST DC A(PG,CX,II) parmlist
REPEATSA DS 7F local savearea
MVCX MVC 0(0,R2),0(R3) move @ R3 to @ R2
C24 DC 6C'xyz ' constant repeat - repeat('xyz ',6)
LCX DC AL2(L'CX) lengh(cc)
CX DC CL4'abc ' cx
II DC F'6' ii
PG DC CL80' ' pg
REGEQU
END REPEATS

View file

@ -0,0 +1,10 @@
gosub repeat ha 5
echo %@repeat[*,5]
quit
:Repeat [String Times]
do %Times%
echos %String%
enddo
echo.
return

View file

@ -0,0 +1,43 @@
CHROUT equ $FFD2 ;KERNAL call, prints the accumulator to the screen as an ascii value.
org $0801
db $0E,$08,$0A,$00,$9E,$20,$28,$32,$30,$36,$34,$29,$00,$00,$00
lda #>TestStr
sta $11
lda #<TestStr
sta $10
ldx #5 ;number of times to repeat
loop:
jsr PrintString
dex
bne loop
RTS ;RETURN TO BASIC
PrintString:
ldy #0
loop_PrintString:
lda ($10),y ;this doesn't actually increment the pointer itself, so we don't need to back it up.
beq donePrinting
jsr CHROUT
iny
jmp loop_PrintString
donePrinting:
rts
TestStr:
db "HA",0

View file

@ -0,0 +1,12 @@
MOVE.W #5-1,D1
RepString:
LEA A3, MyString
MOVE.L A3,-(SP) ;PUSH A3
JSR PrintString ;unimplemented hardware-dependent printing routine, assumed to not clobber D1
MOVE.L (SP)+,A3 ;POP A3
DBRA D1,RepString
RTS ;return to basic or whatever
MyString:
DC.B "ha",0
even

View file

@ -0,0 +1,2 @@
"ha" 5 s:*
. cr

View file

@ -0,0 +1,3 @@
report z_repeat_string.
write repeat( val = `ha` occ = 5 ).

View file

@ -0,0 +1 @@
print (5 * "ha")

View file

@ -0,0 +1,2 @@
10'ha'
hahahahaha

View file

@ -0,0 +1,3 @@
REPEAT{(×)}
5 REPEAT 'ha'
hahahahaha

View file

@ -0,0 +1,10 @@
function repeat( str, n, rep, i )
{
for( ; i<n; i++ )
rep = rep str
return rep
}
BEGIN {
print repeat( "ha", 5 )
}

View file

@ -0,0 +1,11 @@
Proc Main()
byte REPEAT
REPEAT=5
Do
Print("ha")
REPEAT==-1
Until REPEAT=0
Do
Return

View file

@ -0,0 +1,7 @@
function repeatString(string:String, numTimes:uint):String
{
var output:String = "";
for(var i:uint = 0; i < numTimes; i++)
output += string;
return output;
}

View file

@ -0,0 +1,7 @@
function repeatRecursive(string:String, numTimes:uint):String
{
if(numTimes == 0) return "";
if(numTimes & 1) return string + repeatRecursive(string, numTimes - 1);
var tmp:String = repeatRecursive(string, numTimes/2);
return tmp + tmp;
}

View file

@ -0,0 +1,2 @@
import mx.utils.StringUtil;
trace(StringUtil.repeat("ha", 5));

View file

@ -0,0 +1,7 @@
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
procedure String_Multiplication is
begin
Put_Line (5 * "ha");
end String_Multiplication;

View file

@ -0,0 +1 @@
call_n(5, o_text, "ha");

View file

@ -0,0 +1,7 @@
#!/usr/bin/hopper
#include <hopper.h>
main:
{"ha"}replyby(5), println
{"ha",5}replicate, println
{0}return

View file

@ -0,0 +1,5 @@
set str to "ha"
set final_string to ""
repeat 5 times
set final_string to final_string & str
end repeat

View file

@ -0,0 +1,20 @@
replicate(5000, "ha")
-- Repetition by 'Egyptian multiplication' -
-- progressively doubling a list, appending
-- stages of doubling to an accumulator where needed for
-- binary assembly of a target length.
-- replicate :: Int -> String -> String
on replicate(n, s)
set out to ""
if n < 1 then return out
set dbl to s
repeat while (n > 1)
if (n mod 2) > 0 then set out to out & dbl
set n to (n div 2)
set dbl to (dbl & dbl)
end repeat
return out & dbl
end replicate

View file

@ -0,0 +1,3 @@
FOR I = 1 TO 5 : S$ = S$ + "HA" : NEXT
? "X" SPC(20) "X"

View file

@ -0,0 +1 @@
print repeat "ha" 5

View file

@ -0,0 +1,8 @@
MsgBox % Repeat("ha",5)
Repeat(String,Times)
{
Loop, %Times%
Output .= String
Return Output
}

View file

@ -0,0 +1,3 @@
#include <String.au3>
ConsoleWrite(_StringRepeat("ha", 5) & @CRLF)

View file

@ -0,0 +1,12 @@
function StringRepeat$ (s$, n)
cad$ = ""
for i = 1 to n
cad$ += s$
next i
return cad$
end function
print StringRepeat$("rosetta", 1)
print StringRepeat$("ha", 5)
print StringRepeat$("*", 5)
end

View file

@ -0,0 +1 @@
PRINT STRING$(5, "ha")

View file

@ -0,0 +1,3 @@
Repeat ×
•Show 5 Repeat "Hello"

View file

@ -0,0 +1 @@
"HelloHelloHelloHelloHello"

View file

@ -0,0 +1,4 @@
DOTIMES 5
s$ = s$ & "ha"
DONE
PRINT s$

View file

@ -0,0 +1 @@
PRINT FILL$(5, ASC("x"))

View file

@ -0,0 +1,3 @@
main: { "ha" 5 print_repeat }
print_repeat!: { <- { dup << } -> times }

View file

@ -0,0 +1 @@
hahahahaha

View file

@ -0,0 +1,8 @@
@echo off
if "%2" equ "" goto fail
setlocal enabledelayedexpansion
set char=%1
set num=%2
for /l %%i in (1,1,%num%) do set res=!res!%char%
echo %res%
:fail

View file

@ -0,0 +1,10 @@
@echo off
set /p a=Enter string to repeat :
set /p b=Enter how many times to repeat :
set "c=1"
set "d=%b%"
:a
echo %a%
set "c=%c%+=1"
if /i _"%c%"==_"%d%" (exit /b)
goto :a

View file

@ -0,0 +1,13 @@
@echo off
@FOR /L %%i in (0,1,9) DO @CALL :REPEAT %%i
@echo That's it!
@FOR /L %%i in (0,1,9) DO @CALL :REPEAT %%i
@echo.
@echo And that!
@GOTO END
:REPEAT
@echo|set /p="*"
@GOTO:EOF
:END

View file

@ -0,0 +1,2 @@
String s = new String('X', 5);
s.Replace("X", "ha");

View file

@ -0,0 +1,2 @@
String s1 = scope .();
s1.PadLeft(5, '*');

View file

@ -0,0 +1,3 @@
p <
p0~1<}~< d@<
_VT@1~>yg~9PKd@M'd;

View file

@ -0,0 +1,4 @@
v> ">:#,_v
>29*+00p>~:"0"- #v_v $
v ^p0p00:-1g00< $ >
v p00&p0-1g00+4*65< >00g1-:00p#^_@

View file

@ -0,0 +1,8 @@
(repeat=
string N rep
. !arg:(?string.?N)
& !string:?rep
& whl
' (!N+-1:>0:?N&!string !rep:?rep)
& str$!rep
);

View file

@ -0,0 +1,9 @@
+++++ +++++ init first as 10 counter
[-> +++++ +++++<] we add 10 to second each loopround
Now we want to loop 5 times to follow std
+++++
[-> ++++ . ----- -- . +++<] print h and a each loop
and a newline because I'm kind and it looks good
+++++ +++++ +++ . --- .

View file

@ -0,0 +1 @@
p "ha" * 5 #Prints "hahahahaha"

View file

@ -0,0 +1,4 @@
blsq ) 'h5?*
"hhhhh"
blsq ) "ha"5.*\[
"hahahahaha"

View file

@ -0,0 +1,15 @@
#include <string>
#include <iostream>
std::string repeat( const std::string &word, int times ) {
std::string result ;
result.reserve(times*word.length()); // avoid repeated reallocation
for ( int a = 0 ; a < times ; a++ )
result += word ;
return result ;
}
int main( ) {
std::cout << repeat( "Ha" , 5 ) << std::endl ;
return 0 ;
}

View file

@ -0,0 +1,7 @@
#include <string>
#include <iostream>
int main( ) {
std::cout << std::string( 5, '*' ) << std::endl ;
return 0 ;
}

View file

@ -0,0 +1,16 @@
#include <string>
#include <iostream>
std::string repeat( const std::string &word, uint times ) {
return
times == 0 ? "" :
times == 1 ? word :
times == 2 ? word + word :
repeat(repeat(word, times / 2), 2) +
repeat(word, times % 2);
}
int main( ) {
std::cout << repeat( "Ha" , 5 ) << std::endl ;
return 0 ;
}

View file

@ -0,0 +1 @@
string s = "".PadLeft(5, 'X').Replace("X", "ha");

View file

@ -0,0 +1 @@
string s = new String('X', 5).Replace("X", "ha");

View file

@ -0,0 +1 @@
string s = String.Join("ha", new string[5 + 1]);

View file

@ -0,0 +1 @@
string s = String.Concat(Enumerable.Repeat("ha", 5));

View file

@ -0,0 +1 @@
string s = "".PadLeft(5, '*');

View file

@ -0,0 +1 @@
string s = new String('*', 5);

View file

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * string_repeat( int n, const char * s ) {
size_t slen = strlen(s);
char * dest = malloc(n*slen+1);
int i; char * p;
for ( i=0, p = dest; i < n; ++i, p += slen ) {
memcpy(p, s, slen);
}
*p = '\0';
return dest;
}
int main() {
char * result = string_repeat(5, "ha");
puts(result);
free(result);
return 0;
}

View file

@ -0,0 +1,13 @@
...
char *string_repeat(const char *str, int n)
{
char *pa, *pb;
size_t slen = strlen(str);
char *dest = malloc(n*slen+1);
pa = dest + (n-1)*slen;
strcpy(pa, str);
pb = --pa + slen;
while (pa>=dest) *pa-- = *pb--;
return dest;
}

View file

@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * char_repeat( int n, char c ) {
char * dest = malloc(n+1);
memset(dest, c, n);
dest[n] = '\0';
return dest;
}
int main() {
char * result = char_repeat(5, '*');
puts(result);
free(result);
return 0;
}

View file

@ -0,0 +1,9 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. REPEAT-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 HAHA PIC A(10).
PROCEDURE DIVISION.
MOVE ALL 'ha' TO HAHA.
DISPLAY HAHA.
STOP RUN.

View file

@ -0,0 +1,3 @@
shared void repeatAString() {
print("ha".repeat(5));
}

View file

@ -0,0 +1 @@
Replicate( "Ha", 5 )

View file

@ -0,0 +1 @@
(apply str (repeat 5 "ha"))

View file

@ -0,0 +1,5 @@
<cfset word = 'ha'>
<Cfset n = 5>
<Cfoutput>
<Cfloop from="1" to="#n#" index="i">#word#</Cfloop>
</Cfoutput>

View file

@ -0,0 +1,3 @@
(defun repeat-string (n string)
(with-output-to-string (stream)
(loop repeat n do (write-string string stream))))

View file

@ -0,0 +1,9 @@
(defun repeat-string (n string
&aux
(len (length string))
(result (make-string (* n len)
:element-type (array-element-type string))))
(loop repeat n
for i from 0 by len
do (setf (subseq result i (+ i len)) string))
result)

View file

@ -0,0 +1,2 @@
(defun repeat-string (n string)
(format nil "~V@{~a~:*~}" n string))

View file

@ -0,0 +1 @@
(princ (repeat-string 5 "hi"))

View file

@ -0,0 +1 @@
(make-string 5 :initial-element #\X)

View file

@ -0,0 +1 @@
puts "ha" * 5

View file

@ -0,0 +1,5 @@
import std.stdio, std.array;
void main() {
writeln("ha".replicate(5));
}

View file

@ -0,0 +1,8 @@
import std.stdio;
void main() {
char[] chars; // create the dynamic array
chars.length = 5; // set the length
chars[] = '*'; // set all characters in the string to '*'
writeln(chars);
}

View file

@ -0,0 +1,2 @@
$ write sys$output f$fao( "!AS!-!AS!-!AS!-!AS!-!AS", "ha" )
$ write sys$output f$fao( "!12*d" )

View file

@ -0,0 +1 @@
PrintLn( StringOfString('abc',5) );

View file

@ -0,0 +1 @@
PrintLn( StringOfChar('a',5) );

View file

@ -0,0 +1,9 @@
function RepeatString(const s: string; count: cardinal): string;
var
i: Integer;
begin
for i := 1 to count do
Result := Result + s;
end;
Writeln(RepeatString('ha',5));

View file

@ -0,0 +1 @@
Writeln( StringOfChar('a',5) );

View file

@ -0,0 +1,7 @@
function RepeatStr(const s: string; i: Cardinal): string;
begin
if i = 0 then
result := ''
else
result := s + RepeatStr(s, i-1)
end;

View file

@ -0,0 +1 @@
StrUtils.DupeString

View file

@ -0,0 +1 @@
String.Repeat("ha", 5)

View file

@ -0,0 +1 @@
"ha" * 5

View file

@ -0,0 +1,5 @@
IMPORT STD; //Imports the Standard Library
STRING MyBaseString := 'abc';
RepeatedString := STD.Str.Repeat(MyBaseString,3);
RepeatedString; //returns 'abcabcabc'

View file

@ -0,0 +1,9 @@
RepeatString(STRING InStr, INTEGER Cnt) := FUNCTION
rec := {STRING Str};
ds := DATASET(Cnt,TRANSFORM(rec,SELF.Str := InStr));
res := ITERATE(ds,TRANSFORM(rec,SELF.Str := LEFT.Str + RIGHT.Str));
RETURN Res[Cnt].Str;
END;
RepeatString('ha',3);
RepeatString('Who',2);

View file

@ -0,0 +1,7 @@
PROCEDURE REPEAT_STRING(S$,N%->REP$)
LOCAL I%
REP$=""
FOR I%=1 TO N% DO
REP$=REP$+S$
END FOR
END PROCEDURE

View file

@ -0,0 +1,2 @@
String funny = "ha" * 5;
String stars = '*' * 80;

View file

@ -0,0 +1 @@
(S.concat (take 5 (repeat1 "ha")))

View file

@ -0,0 +1,6 @@
repeat_string(a_string: STRING; times: INTEGER): STRING
require
times_positive: times > 0
do
Result := a_string.multiply(times)
end

View file

@ -0,0 +1,8 @@
import system'routines;
import extensions;
import extensions'text;
public program()
{
var s := new Range(0, 5).selectBy:(x => "ha").summarize(new StringWriter())
}

View file

@ -0,0 +1 @@
String.duplicate("ha", 5)

View file

@ -0,0 +1 @@
(apply 'concat (make-list 5 "ha"))

View file

@ -0,0 +1 @@
(make-string 5 ?x)

View file

@ -0,0 +1,2 @@
(require 'cl-lib)
(cl-loop repeat 5 concat "ha")

View file

@ -0,0 +1,2 @@
repeat(X,N) ->
lists:flatten(lists:duplicate(N,X)).

View file

@ -0,0 +1,5 @@
sequence s = ""
for i = 1 to 5 do s &= "ha" end for
puts(1,s)
hahahahaha

View file

@ -0,0 +1,3 @@
sequence s = repeat('*',5)
*****

View file

@ -0,0 +1,9 @@
include std/console.e -- for display
include std/sequence.e -- for repeat_pattern
sequence s = repeat_pattern("ha",5)
sequence n = repeat_pattern({1,2,3},5)
display(s)
display(n)
hahahahaha
{1,2,3,1,2,3,1,2,3,1,2,3,1,2,3}

View file

@ -0,0 +1,4 @@
include std/console.e -- for display
include std/sequence.e -- for flatten
sequence s = flatten(repeat("ha",5))
display(s)

View file

@ -0,0 +1,7 @@
{
"ha",
"ha",
"ha",
"ha",
"ha"
}

View file

@ -0,0 +1,2 @@
> String.replicate 5 "ha";;
val it : string = "hahahahaha"

View file

@ -0,0 +1,2 @@
> String.Concat( Array.create 5 "ha" );;
val it : string = "hahahahaha"

View file

@ -0,0 +1,3 @@
: repeat-string ( str n -- str' ) swap <repetition> concat ;
"ha" 5 repeat-string print

View file

@ -0,0 +1,6 @@
: place-n { src len dest n -- }
0 dest c!
n 0 ?do src len dest +place loop ;
s" ha" pad 5 place-n
pad count type \ hahahahaha

Some files were not shown because too many files have changed in this diff Show more