Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
7
Task/Copy-a-string/00-META.yaml
Normal file
7
Task/Copy-a-string/00-META.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
- Simple
|
||||
- Strings
|
||||
from: http://rosettacode.org/wiki/Copy_a_string
|
||||
note: Basic language learning
|
||||
11
Task/Copy-a-string/00-TASK.txt
Normal file
11
Task/Copy-a-string/00-TASK.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
This task is about copying a string.
|
||||
|
||||
|
||||
;Task:
|
||||
Where it is relevant, distinguish between copying the contents of a string
|
||||
versus making an additional reference to an existing string.
|
||||
|
||||
|
||||
{{Template:Strings}}
|
||||
<br><br>
|
||||
|
||||
2
Task/Copy-a-string/11l/copy-a-string.11l
Normal file
2
Task/Copy-a-string/11l/copy-a-string.11l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
V src = ‘hello’
|
||||
V dst = copy(src)
|
||||
17
Task/Copy-a-string/360-Assembly/copy-a-string.360
Normal file
17
Task/Copy-a-string/360-Assembly/copy-a-string.360
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
* Duplicate a string
|
||||
MVC A,=CL64'Hello' a='Hello'
|
||||
MVC B,A b=a memory copy
|
||||
MVC A,=CL64'Goodbye' a='Goodbye'
|
||||
XPRNT A,L'A print a
|
||||
XPRNT B,L'B print b
|
||||
...
|
||||
* Make reference to a string a string
|
||||
MVC A,=CL64'Hi!' a='Hi!'
|
||||
LA R1,A r1=@a set pointer
|
||||
ST R1,REFA refa=@a store pointer
|
||||
XPRNT A,L'A print a
|
||||
XPRNT 0(R1),L'A print %refa
|
||||
...
|
||||
A DS CL64 a
|
||||
B DS CL64 b
|
||||
REFA DS A @a
|
||||
35
Task/Copy-a-string/6502-Assembly/copy-a-string.6502
Normal file
35
Task/Copy-a-string/6502-Assembly/copy-a-string.6502
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
source equ $10 ;$10 was chosen arbitrarily
|
||||
source_hi equ source+1 ;the high byte MUST be after the low byte, otherwise this will not work.
|
||||
dest equ $12
|
||||
dest_hi equ dest+1
|
||||
|
||||
LDA #<MyString ;get the low byte of &MyString
|
||||
STA source
|
||||
LDA #>MyString ;get the high byte
|
||||
STA source_hi ;we just created a "shallow reference" to an existing string.
|
||||
;As it turns out, this is a necessary step to do a deep copy.
|
||||
|
||||
LDA #<RamBuffer
|
||||
STA dest
|
||||
LDA #>RamBuffer
|
||||
STA dest_hi
|
||||
|
||||
|
||||
strcpy:
|
||||
;assumes that RamBuffer is big enough to hold the source string, and that the memory ranges do not overlap.
|
||||
;if you've ever wondered why C's strcpy is considered "unsafe", this is why.
|
||||
|
||||
LDY #0
|
||||
.again:
|
||||
LDA (source),y
|
||||
STA (dest),y
|
||||
BEQ .done
|
||||
INY
|
||||
BNE .again ;exit after 256 bytes copied or the null terminator is reached, whichever occurs first.
|
||||
RTS
|
||||
|
||||
|
||||
MyString:
|
||||
byte "hello",0
|
||||
RamBuffer:
|
||||
byte 0,0,0,0,0,0
|
||||
4
Task/Copy-a-string/68000-Assembly/copy-a-string-1.68000
Normal file
4
Task/Copy-a-string/68000-Assembly/copy-a-string-1.68000
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
myString: DC.B "HELLO WORLD",0
|
||||
EVEN
|
||||
|
||||
LEA myString,A3
|
||||
16
Task/Copy-a-string/68000-Assembly/copy-a-string-2.68000
Normal file
16
Task/Copy-a-string/68000-Assembly/copy-a-string-2.68000
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
StringRam equ $100000
|
||||
|
||||
myString: DC.B "HELLO WORLD",0
|
||||
EVEN
|
||||
|
||||
LEA myString,A3
|
||||
LEA StringRam,A4
|
||||
|
||||
CopyString:
|
||||
MOVE.B (A3)+,D0
|
||||
MOVE.B D0,(A4)+ ;we could have used "MOVE.B (A3)+,(A4)+" but this makes it easier to check for the terminator.
|
||||
BEQ Terminated
|
||||
BRA CopyString
|
||||
|
||||
Terminated: ;the null terminator is already stored along with the string itself, so we are done.
|
||||
;program ends here.
|
||||
20
Task/Copy-a-string/8086-Assembly/copy-a-string-1.8086
Normal file
20
Task/Copy-a-string/8086-Assembly/copy-a-string-1.8086
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
.model small
|
||||
.stack 1024
|
||||
|
||||
.data
|
||||
|
||||
myString byte "Hello World!",0 ; a null-terminated string
|
||||
|
||||
myStruct word 0
|
||||
|
||||
.code
|
||||
|
||||
mov ax,@data
|
||||
mov ds,ax ;load data segment into DS
|
||||
|
||||
mov bx,offset myString ;get the pointer to myString
|
||||
|
||||
mov word ptr [ds:myStruct],bx
|
||||
|
||||
mov ax,4C00h
|
||||
int 21h ;quit program and return to DOS
|
||||
28
Task/Copy-a-string/8086-Assembly/copy-a-string-2.8086
Normal file
28
Task/Copy-a-string/8086-Assembly/copy-a-string-2.8086
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
.model small
|
||||
.stack 1024
|
||||
|
||||
.data
|
||||
|
||||
myString byte "Hello World!",0 ; a null-terminated string
|
||||
|
||||
StringRam byte 256 dup (0) ;256 null bytes
|
||||
|
||||
.code
|
||||
|
||||
mov ax,@data
|
||||
mov ds,ax ;load data segment into DS
|
||||
mov es,ax ;also load it into ES
|
||||
|
||||
mov si,offset myString
|
||||
mov di,offset StringRam
|
||||
mov cx,12 ;length of myString
|
||||
cld ;make MOVSB auto-increment rather than auto-decrement (I'm pretty sure DOS begins with
|
||||
;the direction flag cleared but just to be safe)
|
||||
|
||||
rep movsb ;copies 12 bytes from [ds:si] to [es:di]
|
||||
mov al,0 ;create a null terminator
|
||||
stosb ;store at the end. (It's already there since we initialized StringRam to zeroes, but you may need to do this depending
|
||||
;on what was previously stored in StringRam, if you've copied a string there already.
|
||||
|
||||
mov ax,4C00h
|
||||
int 21h ;quit program and return to DOS
|
||||
62
Task/Copy-a-string/AArch64-Assembly/copy-a-string.aarch64
Normal file
62
Task/Copy-a-string/AArch64-Assembly/copy-a-string.aarch64
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program copystr64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
/*******************************************/
|
||||
/* Initialized data */
|
||||
/*******************************************/
|
||||
.data
|
||||
szString: .asciz "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
|
||||
/*******************************************/
|
||||
/* UnInitialized data */
|
||||
/*******************************************/
|
||||
.bss
|
||||
.align 4
|
||||
qPtString: .skip 8
|
||||
szString1: .skip 80
|
||||
/*******************************************/
|
||||
/* code section */
|
||||
/*******************************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
|
||||
// display start string
|
||||
ldr x0,qAdrszString
|
||||
bl affichageMess
|
||||
// copy pointer string
|
||||
ldr x0,qAdrszString
|
||||
ldr x1,qAdriPtString
|
||||
str x0,[x1]
|
||||
// control
|
||||
ldr x1,qAdriPtString
|
||||
ldr x0,[x1]
|
||||
bl affichageMess
|
||||
// copy string
|
||||
ldr x0,qAdrszString
|
||||
ldr x1,qAdrszString1
|
||||
1:
|
||||
ldrb w2,[x0],1 // read one byte and increment pointer one byte
|
||||
strb w2,[x1],1 // store one byte and increment pointer one byte
|
||||
cmp x2,#0 // end of string ?
|
||||
bne 1b // no -> loop
|
||||
// control
|
||||
ldr x0,qAdrszString1
|
||||
bl affichageMess
|
||||
|
||||
100: // standard end of the program */
|
||||
mov x0,0 // return code
|
||||
mov x8,EXIT // request to exit program
|
||||
svc 0 // perform the system call
|
||||
qAdrszString: .quad szString
|
||||
qAdriPtString: .quad qPtString
|
||||
qAdrszString1: .quad szString1
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
3
Task/Copy-a-string/ABAP/copy-a-string-1.abap
Normal file
3
Task/Copy-a-string/ABAP/copy-a-string-1.abap
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
data: lv_string1 type string value 'Test',
|
||||
lv_string2 type string.
|
||||
lv_string2 = lv_string1.
|
||||
2
Task/Copy-a-string/ABAP/copy-a-string-2.abap
Normal file
2
Task/Copy-a-string/ABAP/copy-a-string-2.abap
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DATA(string1) = |Test|.
|
||||
DATA(string2) = string1.
|
||||
4
Task/Copy-a-string/ALGOL-68/copy-a-string.alg
Normal file
4
Task/Copy-a-string/ALGOL-68/copy-a-string.alg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(
|
||||
STRING src:="Hello", dest;
|
||||
dest:=src
|
||||
)
|
||||
9
Task/Copy-a-string/ALGOL-W/copy-a-string.alg
Normal file
9
Task/Copy-a-string/ALGOL-W/copy-a-string.alg
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
begin
|
||||
% strings are (fixed length) values in algol W. Assignment makes a copy %
|
||||
string(10) a, copyOfA;
|
||||
a := "some text";
|
||||
copyOfA := a;
|
||||
% assignment to a will not change copyOfA %
|
||||
a := "new value";
|
||||
write( a, copyOfA )
|
||||
end.
|
||||
76
Task/Copy-a-string/ARM-Assembly/copy-a-string.arm
Normal file
76
Task/Copy-a-string/ARM-Assembly/copy-a-string.arm
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program copystr.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
/* Initialized data */
|
||||
.data
|
||||
szString: .asciz "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
|
||||
|
||||
/* UnInitialized data */
|
||||
.bss
|
||||
.align 4
|
||||
iPtString: .skip 4
|
||||
szString1: .skip 80
|
||||
|
||||
/* code section */
|
||||
.text
|
||||
.global main
|
||||
main: /* entry of program */
|
||||
push {fp,lr} /* saves 2 registers */
|
||||
|
||||
@ display start string
|
||||
ldr r0,iAdrszString
|
||||
bl affichageMess
|
||||
@ copy pointer string
|
||||
ldr r0,iAdrszString
|
||||
ldr r1,iAdriPtString
|
||||
str r0,[r1]
|
||||
@ control
|
||||
ldr r1,iAdriPtString
|
||||
ldr r0,[r1]
|
||||
bl affichageMess
|
||||
@ copy string
|
||||
ldr r0,iAdrszString
|
||||
ldr r1,iAdrszString1
|
||||
1:
|
||||
ldrb r2,[r0],#1 @ read one byte and increment pointer one byte
|
||||
strb r2,[r1],#1 @ store one byte and increment pointer one byte
|
||||
cmp r2,#0 @ end of string ?
|
||||
bne 1b @ no -> loop
|
||||
@ control
|
||||
ldr r0,iAdrszString1
|
||||
bl affichageMess
|
||||
|
||||
100: /* standard end of the program */
|
||||
mov r0, #0 @ return code
|
||||
pop {fp,lr} @restaur 2 registers
|
||||
mov r7, #EXIT @ request to exit program
|
||||
swi 0 @ perform the system call
|
||||
iAdrszString: .int szString
|
||||
iAdriPtString: .int iPtString
|
||||
iAdrszString1: .int szString1
|
||||
|
||||
/******************************************************************/
|
||||
/* display text with size calculation */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the message */
|
||||
affichageMess:
|
||||
push {fp,lr} /* save registres */
|
||||
push {r0,r1,r2,r7} /* save others registers */
|
||||
mov r2,#0 /* counter length */
|
||||
1: /* loop length calculation */
|
||||
ldrb r1,[r0,r2] /* read octet start position + index */
|
||||
cmp r1,#0 /* if 0 its over */
|
||||
addne r2,r2,#1 /* else add 1 in the length */
|
||||
bne 1b /* and loop */
|
||||
/* so here r2 contains the length of the message */
|
||||
mov r1,r0 /* address message in r1 */
|
||||
mov r0,#STDOUT /* code to write to the standard output Linux */
|
||||
mov r7, #WRITE /* code call system "write" */
|
||||
swi #0 /* call systeme */
|
||||
pop {r0,r1,r2,r7} /* restaur others registers */
|
||||
pop {fp,lr} /* restaur des 2 registres */
|
||||
bx lr /* return */
|
||||
6
Task/Copy-a-string/AWK/copy-a-string.awk
Normal file
6
Task/Copy-a-string/AWK/copy-a-string.awk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
BEGIN {
|
||||
a = "a string"
|
||||
b = a
|
||||
sub(/a/, "X", a) # modify a
|
||||
print b # b is a copy, not a reference to...
|
||||
}
|
||||
18
Task/Copy-a-string/Action-/copy-a-string.action
Normal file
18
Task/Copy-a-string/Action-/copy-a-string.action
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
PROC Main()
|
||||
CHAR ARRAY str1,str2,str3(10)
|
||||
|
||||
str1="Atari"
|
||||
str2=str1
|
||||
SCopy(str3,str1)
|
||||
|
||||
PrintF(" base=%S%E",str1)
|
||||
PrintF("alias=%S%E",str2)
|
||||
PrintF(" copy=%S%E",str3)
|
||||
PutE()
|
||||
|
||||
SCopy(str1,"Action!")
|
||||
|
||||
PrintF(" base=%S%E",str1)
|
||||
PrintF("alias=%S%E",str2)
|
||||
PrintF(" copy=%S%E",str3)
|
||||
RETURN
|
||||
2
Task/Copy-a-string/ActionScript/copy-a-string.as
Normal file
2
Task/Copy-a-string/ActionScript/copy-a-string.as
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var str1:String = "Hello";
|
||||
var str2:String = str1;
|
||||
2
Task/Copy-a-string/Ada/copy-a-string-1.ada
Normal file
2
Task/Copy-a-string/Ada/copy-a-string-1.ada
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Src : String := "Hello";
|
||||
Dest : String := Src;
|
||||
3
Task/Copy-a-string/Ada/copy-a-string-2.ada
Normal file
3
Task/Copy-a-string/Ada/copy-a-string-2.ada
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Src : String := "Rosetta Stone";
|
||||
Dest : String := Src(1..7); -- Assigns "Rosetta" to Dest
|
||||
Dest2 : String := Src(9..13); -- Assigns "Stone" to Dest2
|
||||
6
Task/Copy-a-string/Ada/copy-a-string-3.ada
Normal file
6
Task/Copy-a-string/Ada/copy-a-string-3.ada
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-- Instantiate the generic package Ada.Strings.Bounded.Generic_Bounded_Length with a maximum length of 80 characters
|
||||
package Flexible_String is new Ada.Strings.Bounded.Generic_Bounded_Length(80);
|
||||
use Flexible_String;
|
||||
|
||||
Src : Bounded_String := To_Bounded_String("Hello");
|
||||
Dest : Bounded_String := Src;
|
||||
3
Task/Copy-a-string/Ada/copy-a-string-4.ada
Normal file
3
Task/Copy-a-string/Ada/copy-a-string-4.ada
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
-- The package Ada.Strings.Unbounded contains the definition of the Unbounded_String type and all its methods
|
||||
Src : Unbounded_String := To_Unbounded_String("Hello");
|
||||
Dest : Unbounded_String := Src;
|
||||
3
Task/Copy-a-string/Aime/copy-a-string-1.aime
Normal file
3
Task/Copy-a-string/Aime/copy-a-string-1.aime
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
text s, t;
|
||||
t = "Rosetta";
|
||||
s = t;
|
||||
7
Task/Copy-a-string/Aime/copy-a-string-2.aime
Normal file
7
Task/Copy-a-string/Aime/copy-a-string-2.aime
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
data s, t;
|
||||
# Copy -t- into -s-
|
||||
b_copy(s, t);
|
||||
# Set -s- as a reference of the object -t- is pointing
|
||||
b_set(s, t);
|
||||
# or:
|
||||
s = t;
|
||||
6
Task/Copy-a-string/Amazing-Hopper/copy-a-string-1.hopper
Normal file
6
Task/Copy-a-string/Amazing-Hopper/copy-a-string-1.hopper
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <hopper.h>
|
||||
main:
|
||||
s = "string to copy"
|
||||
t = s
|
||||
{s,"\n",t}println
|
||||
exit(0)
|
||||
6
Task/Copy-a-string/Amazing-Hopper/copy-a-string-2.hopper
Normal file
6
Task/Copy-a-string/Amazing-Hopper/copy-a-string-2.hopper
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <hopper.h>
|
||||
main:
|
||||
s=""
|
||||
{"1:","string to copy"},cpy(s),println
|
||||
{"2:",s}println
|
||||
exit(0)
|
||||
6
Task/Copy-a-string/Amazing-Hopper/copy-a-string-3.hopper
Normal file
6
Task/Copy-a-string/Amazing-Hopper/copy-a-string-3.hopper
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <hopper.h>
|
||||
main:
|
||||
s=""
|
||||
{"string to copy"},mov(s)
|
||||
{s}println
|
||||
exit(0)
|
||||
6
Task/Copy-a-string/Apex/copy-a-string.apex
Normal file
6
Task/Copy-a-string/Apex/copy-a-string.apex
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
String original = 'Test';
|
||||
String cloned = original;
|
||||
//"original == cloned" is true
|
||||
|
||||
cloned += ' more';
|
||||
//"original == cloned" is false
|
||||
2
Task/Copy-a-string/AppleScript/copy-a-string.applescript
Normal file
2
Task/Copy-a-string/AppleScript/copy-a-string.applescript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
set src to "Hello"
|
||||
set dst to src
|
||||
4
Task/Copy-a-string/Applesoft-BASIC/copy-a-string-1.basic
Normal file
4
Task/Copy-a-string/Applesoft-BASIC/copy-a-string-1.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
100 DEF FN P(A) = PEEK (A) + PEEK(A + 1) * 256 : FOR I = FN P(105) TO FN P(107) - 1 STEP 7 : ON PEEK(I + 1) < 128 OR PEEK(I) > 127 GOTO 130 : ON LEFT$(P$, 1) <> CHR$(PEEK(I)) GOTO 130
|
||||
110 IF LEN(P$) > 1 THEN ON PEEK(I + 1) = 128 GOTO 130 : IF MID$(P$, 2, 1) <> CHR$(PEEK(I + 1) - 128) GOTO 130
|
||||
120 POKE I + 4, P / 256 : POKE I + 3, P - PEEK(I + 4) * 256 : RETURN
|
||||
130 NEXT I : STOP
|
||||
2
Task/Copy-a-string/Applesoft-BASIC/copy-a-string-2.basic
Normal file
2
Task/Copy-a-string/Applesoft-BASIC/copy-a-string-2.basic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
S$ = "HELLO" : REM S$ IS THE ORIGINAL STRING
|
||||
C$ = S$ : REM C$ IS THE COPY
|
||||
3
Task/Copy-a-string/Applesoft-BASIC/copy-a-string-3.basic
Normal file
3
Task/Copy-a-string/Applesoft-BASIC/copy-a-string-3.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
P$ = "S" : P = 53637 : GOSUB 100"POINT STRING S AT SOMETHING ELSE
|
||||
?S$
|
||||
?C$
|
||||
19
Task/Copy-a-string/Arturo/copy-a-string.arturo
Normal file
19
Task/Copy-a-string/Arturo/copy-a-string.arturo
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
a: new "Hello"
|
||||
b: a ; reference the same string
|
||||
|
||||
; changing one string in-place
|
||||
; will change both strings
|
||||
|
||||
'b ++ "World"
|
||||
print b
|
||||
print a
|
||||
|
||||
c: "Hello"
|
||||
d: new c ; make a copy of the older string
|
||||
|
||||
; changing one string in-place
|
||||
; will change only the string in question
|
||||
|
||||
'd ++ "World"
|
||||
print d
|
||||
print c
|
||||
5
Task/Copy-a-string/Asymptote/copy-a-string.asymptote
Normal file
5
Task/Copy-a-string/Asymptote/copy-a-string.asymptote
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
string src, dst;
|
||||
src = "Hello";
|
||||
dst = src;
|
||||
src = " world...";
|
||||
write(dst, src);
|
||||
2
Task/Copy-a-string/AutoHotkey/copy-a-string.ahk
Normal file
2
Task/Copy-a-string/AutoHotkey/copy-a-string.ahk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src := "Hello"
|
||||
dst := src
|
||||
2
Task/Copy-a-string/AutoIt/copy-a-string.autoit
Normal file
2
Task/Copy-a-string/AutoIt/copy-a-string.autoit
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$Src= "Hello"
|
||||
$dest = $Src
|
||||
10
Task/Copy-a-string/Axe/copy-a-string.axe
Normal file
10
Task/Copy-a-string/Axe/copy-a-string.axe
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Lbl STRCPY
|
||||
r₁→S
|
||||
While {r₂}
|
||||
{r₂}→{r₁}
|
||||
r₁++
|
||||
r₂++
|
||||
End
|
||||
0→{r₁}
|
||||
S
|
||||
Return
|
||||
4
Task/Copy-a-string/BASIC256/copy-a-string.basic
Normal file
4
Task/Copy-a-string/BASIC256/copy-a-string.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
src$ = "Hello"
|
||||
dst$ = src$
|
||||
src$ = " world..."
|
||||
print dst$; src$
|
||||
11
Task/Copy-a-string/BBC-BASIC/copy-a-string.basic
Normal file
11
Task/Copy-a-string/BBC-BASIC/copy-a-string.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
source$ = "Hello, world!"
|
||||
|
||||
REM Copy the contents of a string:
|
||||
copy$ = source$
|
||||
PRINT copy$
|
||||
|
||||
REM Make an additional reference to a string:
|
||||
!^same$ = !^source$
|
||||
?(^same$+4) = ?(^source$+4)
|
||||
?(^same$+5) = ?(^source$+5)
|
||||
PRINT same$
|
||||
5
Task/Copy-a-string/BQN/copy-a-string-1.bqn
Normal file
5
Task/Copy-a-string/BQN/copy-a-string-1.bqn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a ← "Hello"
|
||||
b ← a
|
||||
•Show a‿b
|
||||
a ↩ "hi"
|
||||
•Show a‿b
|
||||
2
Task/Copy-a-string/BQN/copy-a-string-2.bqn
Normal file
2
Task/Copy-a-string/BQN/copy-a-string-2.bqn
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
⟨ "Hello" "Hello" ⟩
|
||||
⟨ "hi" "Hello" ⟩
|
||||
4
Task/Copy-a-string/BaCon/copy-a-string-1.bacon
Normal file
4
Task/Copy-a-string/BaCon/copy-a-string-1.bacon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
a$ = "I am here"
|
||||
b$ = a$
|
||||
a$ = "Hello world..."
|
||||
PRINT a$, b$
|
||||
5
Task/Copy-a-string/BaCon/copy-a-string-2.bacon
Normal file
5
Task/Copy-a-string/BaCon/copy-a-string-2.bacon
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a$ = "Hello world..."
|
||||
LOCAL b TYPE STRING
|
||||
b = a$
|
||||
a$ = "Goodbye..."
|
||||
PRINT a$, b
|
||||
4
Task/Copy-a-string/Babel/copy-a-string.pb
Normal file
4
Task/Copy-a-string/Babel/copy-a-string.pb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
babel> "Hello, world\n" dup cp dup 0 "Y" 0 1 move8
|
||||
babel> << <<
|
||||
Yello, world
|
||||
Hello, world
|
||||
2
Task/Copy-a-string/Batch-File/copy-a-string.bat
Normal file
2
Task/Copy-a-string/Batch-File/copy-a-string.bat
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
set src=Hello
|
||||
set dst=%src%
|
||||
8
Task/Copy-a-string/Bracmat/copy-a-string.bracmat
Normal file
8
Task/Copy-a-string/Bracmat/copy-a-string.bracmat
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
abcdef:?a;
|
||||
!a:?b;
|
||||
|
||||
c=abcdef;
|
||||
!c:?d;
|
||||
|
||||
!a:!b { variables a and b are the same and probably referencing the same string }
|
||||
!a:!d { variables a and d are also the same but not referencing the same string }
|
||||
10
Task/Copy-a-string/C++/copy-a-string.cpp
Normal file
10
Task/Copy-a-string/C++/copy-a-string.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main( ) {
|
||||
std::string original ("This is the original");
|
||||
std::string my_copy = original;
|
||||
std::cout << "This is the copy: " << my_copy << std::endl;
|
||||
original = "Now we change the original! ";
|
||||
std::cout << "my_copy still is " << my_copy << std::endl;
|
||||
}
|
||||
2
Task/Copy-a-string/C-sharp/copy-a-string.cs
Normal file
2
Task/Copy-a-string/C-sharp/copy-a-string.cs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
string src = "Hello";
|
||||
string dst = src;
|
||||
60
Task/Copy-a-string/C/copy-a-string-1.c
Normal file
60
Task/Copy-a-string/C/copy-a-string-1.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include <stdlib.h> /* exit(), free() */
|
||||
#include <stdio.h> /* fputs(), perror(), printf() */
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
size_t len;
|
||||
char src[] = "Hello";
|
||||
char dst1[80], dst2[80];
|
||||
char *dst3, *ref;
|
||||
|
||||
/*
|
||||
* Option 1. Use strcpy() from <string.h>.
|
||||
*
|
||||
* DANGER! strcpy() can overflow the destination buffer.
|
||||
* strcpy() is only safe if the source string is shorter than
|
||||
* the destination buffer. We know that "Hello" (6 characters
|
||||
* with the final '\0') easily fits in dst1 (80 characters).
|
||||
*/
|
||||
strcpy(dst1, src);
|
||||
|
||||
/*
|
||||
* Option 2. Use strlen() and memcpy() from <string.h>, to copy
|
||||
* strlen(src) + 1 bytes including the final '\0'.
|
||||
*/
|
||||
len = strlen(src);
|
||||
if (len >= sizeof dst2) {
|
||||
fputs("The buffer is too small!\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
memcpy(dst2, src, len + 1);
|
||||
|
||||
/*
|
||||
* Option 3. Use strdup() from <string.h>, to allocate a copy.
|
||||
*/
|
||||
dst3 = strdup(src);
|
||||
if (dst3 == NULL) {
|
||||
/* Failed to allocate memory! */
|
||||
perror("strdup");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create another reference to the source string. */
|
||||
ref = src;
|
||||
|
||||
/* Modify the source string, not its copies. */
|
||||
memset(src, '-', 5);
|
||||
|
||||
printf(" src: %s\n", src); /* src: ----- */
|
||||
printf("dst1: %s\n", dst1); /* dst1: Hello */
|
||||
printf("dst2: %s\n", dst2); /* dst2: Hello */
|
||||
printf("dst3: %s\n", dst3); /* dst3: Hello */
|
||||
printf(" ref: %s\n", ref); /* ref: ----- */
|
||||
|
||||
/* Free memory from strdup(). */
|
||||
free(dst3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
22
Task/Copy-a-string/C/copy-a-string-2.c
Normal file
22
Task/Copy-a-string/C/copy-a-string-2.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdlib.h> /* exit() */
|
||||
#include <stdio.h> /* fputs(), printf() */
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char src[] = "Hello";
|
||||
char dst[80];
|
||||
|
||||
/* Use strlcpy() from <string.h>. */
|
||||
if (strlcpy(dst, src, sizeof dst) >= sizeof dst) {
|
||||
fputs("The buffer is too small!\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(src, '-', 5);
|
||||
printf("src: %s\n", src); /* src: ----- */
|
||||
printf("dst: %s\n", dst); /* dst: Hello */
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
Task/Copy-a-string/C/copy-a-string-3.c
Normal file
23
Task/Copy-a-string/C/copy-a-string-3.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <gadget/gadget.h>
|
||||
|
||||
LIB_GADGET_START
|
||||
|
||||
Main
|
||||
String v, w = "this message is a message";
|
||||
|
||||
Let( v, "Hello world!");
|
||||
Print "v = %s\nw = %s\n\n", v,w;
|
||||
|
||||
Get_fn_let( v, Upper(w) );
|
||||
|
||||
Print "v = %s\nw = %s\n\n", v,w;
|
||||
|
||||
Stack{
|
||||
Store ( v, Str_tran_last( Upper(w), "MESSAGE", "PROOF" ) );
|
||||
}Stack_off;
|
||||
|
||||
Print "v = %s\nw = %s\n\n", v,w;
|
||||
|
||||
Free secure v, w;
|
||||
|
||||
End
|
||||
2
Task/Copy-a-string/COBOL/copy-a-string.cobol
Normal file
2
Task/Copy-a-string/COBOL/copy-a-string.cobol
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
MOVE "Hello" TO src
|
||||
MOVE src TO dst
|
||||
3
Task/Copy-a-string/Clojure/copy-a-string.clj
Normal file
3
Task/Copy-a-string/Clojure/copy-a-string.clj
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(let [s "hello"
|
||||
s1 s]
|
||||
(println s s1))
|
||||
2
Task/Copy-a-string/ColdFusion/copy-a-string.cfm
Normal file
2
Task/Copy-a-string/ColdFusion/copy-a-string.cfm
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<cfset stringOrig = "I am a string." />
|
||||
<cfset stringCopy = stringOrig />
|
||||
7
Task/Copy-a-string/Commodore-BASIC/copy-a-string.basic
Normal file
7
Task/Copy-a-string/Commodore-BASIC/copy-a-string.basic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
10 A$ = "HELLO"
|
||||
20 REM COPY CONTENTS OF A$ TO B$
|
||||
30 B$ = A$
|
||||
40 REM CHANGE CONTENTS OF A$
|
||||
50 A$ = "HI"
|
||||
60 REM DISPLAY CONTENTS
|
||||
70 PRINT A$, B$
|
||||
10
Task/Copy-a-string/Common-Lisp/copy-a-string.lisp
Normal file
10
Task/Copy-a-string/Common-Lisp/copy-a-string.lisp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(let* ((s1 "Hello") ; s1 is a variable containing a string
|
||||
(s1-ref s1) ; another variable with the same value
|
||||
(s2 (copy-seq s1))) ; s2 has a distinct string object with the same contents
|
||||
(assert (eq s1 s1-ref)) ; same object
|
||||
(assert (not (eq s1 s2))) ; different object
|
||||
(assert (equal s1 s2)) ; same contents
|
||||
|
||||
(fill s2 #\!) ; overwrite s2
|
||||
(princ s1)
|
||||
(princ s2)) ; will print "Hello!!!!!"
|
||||
4
Task/Copy-a-string/Component-Pascal/copy-a-string-1.pas
Normal file
4
Task/Copy-a-string/Component-Pascal/copy-a-string-1.pas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
VAR
|
||||
str1: ARRAY 128 OF CHAR;
|
||||
str2: ARRAY 32 OF CHAR;
|
||||
str3: ARRAY 25 OF CHAR;
|
||||
4
Task/Copy-a-string/Component-Pascal/copy-a-string-2.pas
Normal file
4
Task/Copy-a-string/Component-Pascal/copy-a-string-2.pas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
str1 := "abcdefghijklmnopqrstuvwxyz";
|
||||
str3 := str1; (* don't compile, incompatible assignement *)
|
||||
str3 := str1$; (* runtime error, string too long *)
|
||||
str2 := str1$; (* OK *)
|
||||
28
Task/Copy-a-string/Computer-zero-Assembly/copy-a-string.0asm
Normal file
28
Task/Copy-a-string/Computer-zero-Assembly/copy-a-string.0asm
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
ldsrc: LDA src
|
||||
stdest: STA dest
|
||||
BRZ done ; 0-terminated
|
||||
|
||||
LDA ldsrc
|
||||
ADD one
|
||||
STA ldsrc
|
||||
|
||||
LDA stdest
|
||||
ADD one
|
||||
STA stdest
|
||||
|
||||
JMP ldsrc
|
||||
|
||||
done: STP
|
||||
|
||||
one: 1
|
||||
|
||||
src: 82 ; ASCII
|
||||
111
|
||||
115
|
||||
101
|
||||
116
|
||||
116
|
||||
97
|
||||
0
|
||||
|
||||
dest:
|
||||
2
Task/Copy-a-string/Crystal/copy-a-string.crystal
Normal file
2
Task/Copy-a-string/Crystal/copy-a-string.crystal
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
s1 = "Hello"
|
||||
s2 = s1
|
||||
12
Task/Copy-a-string/D/copy-a-string.d
Normal file
12
Task/Copy-a-string/D/copy-a-string.d
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
void main() {
|
||||
string src = "This is a string";
|
||||
|
||||
// copy contents:
|
||||
auto dest1 = src.idup;
|
||||
|
||||
// copy contents to mutable char array
|
||||
auto dest2 = src.dup;
|
||||
|
||||
// copy just the fat reference of the string
|
||||
auto dest3 = src;
|
||||
}
|
||||
3
Task/Copy-a-string/Dc/copy-a-string.dc
Normal file
3
Task/Copy-a-string/Dc/copy-a-string.dc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[a string] # push "a string" on the main stack
|
||||
d # duplicate the top value
|
||||
f # show the current contents of the main stack
|
||||
15
Task/Copy-a-string/Delphi/copy-a-string.delphi
Normal file
15
Task/Copy-a-string/Delphi/copy-a-string.delphi
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
program CopyString;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
var
|
||||
s1: string;
|
||||
s2: string;
|
||||
begin
|
||||
s1 := 'Goodbye';
|
||||
s2 := s1; // S2 points at the same string as S1
|
||||
s2 := s2 + ', World!'; // A new string is created for S2
|
||||
|
||||
Writeln(s1);
|
||||
Writeln(s2);
|
||||
end.
|
||||
2
Task/Copy-a-string/Dyalect/copy-a-string.dyalect
Normal file
2
Task/Copy-a-string/Dyalect/copy-a-string.dyalect
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var src = "foobar"
|
||||
var dst = src
|
||||
63
Task/Copy-a-string/EDSAC-order-code/copy-a-string.edsac
Normal file
63
Task/Copy-a-string/EDSAC-order-code/copy-a-string.edsac
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
[ Copy a string
|
||||
=============
|
||||
|
||||
A program for the EDSAC
|
||||
|
||||
Copies the source string into storage
|
||||
tank 6, which is assumed to be free,
|
||||
and then prints it from there
|
||||
|
||||
Works with Initial Orders 2 ]
|
||||
|
||||
T56K
|
||||
GK
|
||||
|
||||
[ 0 ] A34@ [ copy the string ]
|
||||
[ 1 ] T192F
|
||||
[ 2 ] H34@
|
||||
C32@
|
||||
S32@
|
||||
E17@
|
||||
T31@
|
||||
A@
|
||||
A33@
|
||||
T@
|
||||
A1@
|
||||
A33@
|
||||
T1@
|
||||
A2@
|
||||
A33@
|
||||
T2@
|
||||
E@
|
||||
[ 17 ] O192F [ print the copy ]
|
||||
[ 18 ] H192F
|
||||
C32@
|
||||
S32@
|
||||
E30@
|
||||
T31@
|
||||
A17@
|
||||
A33@
|
||||
T17@
|
||||
A18@
|
||||
A33@
|
||||
T18@
|
||||
E17@
|
||||
[ 30 ] ZF
|
||||
[ 31 ] PF
|
||||
[ 32 ] PD
|
||||
[ 33 ] P1F
|
||||
[ 34 ] *F
|
||||
RF
|
||||
OF
|
||||
SF
|
||||
EF
|
||||
TF
|
||||
TF
|
||||
AF
|
||||
!F
|
||||
CF
|
||||
OF
|
||||
DF
|
||||
ED
|
||||
|
||||
EZPF
|
||||
11
Task/Copy-a-string/EMal/copy-a-string.emal
Normal file
11
Task/Copy-a-string/EMal/copy-a-string.emal
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
text original = "Yellow world"
|
||||
text ref = original # copying the reference
|
||||
text copied = *original # copying the content
|
||||
original[0] = "H" # texts are indexable and mutable
|
||||
original[5] = ","
|
||||
ref.append("!") # texts are coercible and growable
|
||||
copied += "?"
|
||||
^|
|
||||
| original == ref == "Hello, world!"
|
||||
| copied == "Yellow world?"
|
||||
|^
|
||||
2
Task/Copy-a-string/EasyLang/copy-a-string.easy
Normal file
2
Task/Copy-a-string/EasyLang/copy-a-string.easy
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a$ = "hello"
|
||||
b$ = a$
|
||||
6
Task/Copy-a-string/EchoLisp/copy-a-string.l
Normal file
6
Task/Copy-a-string/EchoLisp/copy-a-string.l
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(define-syntax-rule (string-copy s) (string-append s)) ;; copy = append nothing
|
||||
→ #syntax:string-copy
|
||||
(define s "abc")
|
||||
(define t (string-copy s))
|
||||
t → "abc"
|
||||
(eq? s t) → #t ;; same reference, same object
|
||||
3
Task/Copy-a-string/Elena/copy-a-string.elena
Normal file
3
Task/Copy-a-string/Elena/copy-a-string.elena
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var src := "Hello";
|
||||
var dst := src; // copying the reference
|
||||
var copy := src.clone(); // copying the content
|
||||
2
Task/Copy-a-string/Elixir/copy-a-string.elixir
Normal file
2
Task/Copy-a-string/Elixir/copy-a-string.elixir
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src = "Hello"
|
||||
dst = src
|
||||
7
Task/Copy-a-string/Emacs-Lisp/copy-a-string.l
Normal file
7
Task/Copy-a-string/Emacs-Lisp/copy-a-string.l
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(let* ((str1 "hi")
|
||||
(str1-ref str1)
|
||||
(str2 (copy-sequence str1)))
|
||||
(eq str1 str1-ref) ;=> t
|
||||
(eq str1 str2) ;=> nil
|
||||
(equal str1 str1-ref) ;=> t
|
||||
(equal str1 str2)) ;=> t
|
||||
2
Task/Copy-a-string/Erlang/copy-a-string.erl
Normal file
2
Task/Copy-a-string/Erlang/copy-a-string.erl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Src = "Hello".
|
||||
Dst = Src.
|
||||
2
Task/Copy-a-string/Euphoria/copy-a-string.euphoria
Normal file
2
Task/Copy-a-string/Euphoria/copy-a-string.euphoria
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
sequence first = "ABC"
|
||||
sequence newOne = first
|
||||
6
Task/Copy-a-string/F-Sharp/copy-a-string.fs
Normal file
6
Task/Copy-a-string/F-Sharp/copy-a-string.fs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
let str = "hello"
|
||||
let additionalReference = str
|
||||
let deepCopy = System.String.Copy( str )
|
||||
|
||||
printfn "%b" <| System.Object.ReferenceEquals( str, additionalReference ) // prints true
|
||||
printfn "%b" <| System.Object.ReferenceEquals( str, deepCopy ) // prints false
|
||||
4
Task/Copy-a-string/Factor/copy-a-string-1.factor
Normal file
4
Task/Copy-a-string/Factor/copy-a-string-1.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"This is a mutable string." dup ! reference
|
||||
"Let's make a deal!" dup clone ! copy
|
||||
"New" " string" append . ! new string
|
||||
"New string"
|
||||
2
Task/Copy-a-string/Factor/copy-a-string-2.factor
Normal file
2
Task/Copy-a-string/Factor/copy-a-string-2.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SBUF" Grow me!" dup " OK." append
|
||||
SBUF" Grow me! OK."
|
||||
2
Task/Copy-a-string/Factor/copy-a-string-3.factor
Normal file
2
Task/Copy-a-string/Factor/copy-a-string-3.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SBUF" I'll be a string someday." >string .
|
||||
"I'll be a string someday."
|
||||
9
Task/Copy-a-string/Forth/copy-a-string.fth
Normal file
9
Task/Copy-a-string/Forth/copy-a-string.fth
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
\ Allocate two string buffers
|
||||
create stringa 256 allot
|
||||
create stringb 256 allot
|
||||
|
||||
\ Copy a constant string into a string buffer
|
||||
s" Hello" stringa place
|
||||
|
||||
\ Copy the contents of one string buffer into another
|
||||
stringa count stringb place
|
||||
1
Task/Copy-a-string/Fortran/copy-a-string.f
Normal file
1
Task/Copy-a-string/Fortran/copy-a-string.f
Normal file
|
|
@ -0,0 +1 @@
|
|||
str2 = str1
|
||||
12
Task/Copy-a-string/FreeBASIC/copy-a-string.basic
Normal file
12
Task/Copy-a-string/FreeBASIC/copy-a-string.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim s As String = "This is a string"
|
||||
Dim t As String = s
|
||||
' a separate copy of the string contents has been made as can be seen from the addresses
|
||||
Print s, StrPtr(s)
|
||||
Print t, StrPtr(t)
|
||||
' to refer to the same string a pointer needs to be used
|
||||
Dim u As String Ptr = @s
|
||||
Print
|
||||
Print *u, StrPtr(*u)
|
||||
Sleep
|
||||
2
Task/Copy-a-string/Frink/copy-a-string.frink
Normal file
2
Task/Copy-a-string/Frink/copy-a-string.frink
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a = "Monkey"
|
||||
b = a
|
||||
10
Task/Copy-a-string/FutureBasic/copy-a-string.basic
Normal file
10
Task/Copy-a-string/FutureBasic/copy-a-string.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
CFStringRef original, copy
|
||||
|
||||
original = @"Hello!"
|
||||
copy = fn StringWithString( original )
|
||||
|
||||
NSLog( @"%@", copy )
|
||||
|
||||
HandleEvents
|
||||
13
Task/Copy-a-string/GAP/copy-a-string.gap
Normal file
13
Task/Copy-a-string/GAP/copy-a-string.gap
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#In GAP strings are lists of characters. An affectation simply copy references
|
||||
a := "more";
|
||||
b := a;
|
||||
b{[1..4]} := "less";
|
||||
a;
|
||||
# "less"
|
||||
|
||||
# Here is a true copy
|
||||
a := "more";
|
||||
b := ShallowCopy(a);
|
||||
b{[1..4]} := "less";
|
||||
a;
|
||||
# "more"
|
||||
2
Task/Copy-a-string/GML/copy-a-string.gml
Normal file
2
Task/Copy-a-string/GML/copy-a-string.gml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src = "string";
|
||||
dest = src;
|
||||
3
Task/Copy-a-string/GUISS/copy-a-string.guiss
Normal file
3
Task/Copy-a-string/GUISS/copy-a-string.guiss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Start.Programs,Accessories,Notepad,
|
||||
Type:Hello world[pling],Highlight:Hello world[pling],
|
||||
Menu,Edit,Copy,Menu,Edit,Paste
|
||||
10
Task/Copy-a-string/Gambas/copy-a-string.gambas
Normal file
10
Task/Copy-a-string/Gambas/copy-a-string.gambas
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Public Sub main()
|
||||
Dim src As String
|
||||
Dim dst As String
|
||||
|
||||
src = "Hello"
|
||||
dst = src
|
||||
|
||||
Print src
|
||||
Print dst
|
||||
End
|
||||
2
Task/Copy-a-string/Go/copy-a-string-1.go
Normal file
2
Task/Copy-a-string/Go/copy-a-string-1.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src := "Hello"
|
||||
dst := src
|
||||
22
Task/Copy-a-string/Go/copy-a-string-2.go
Normal file
22
Task/Copy-a-string/Go/copy-a-string-2.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// creature string
|
||||
var creature string = "shark"
|
||||
// point to creature
|
||||
var pointer *string = &creature
|
||||
// creature string
|
||||
fmt.Println("creature =", creature) // creature = shark
|
||||
// creature location in memory
|
||||
fmt.Println("pointer =", pointer) // pointer = 0xc000010210
|
||||
// creature through the pointer
|
||||
fmt.Println("*pointer =", *pointer) // *pointer = shark
|
||||
// set creature through the pointer
|
||||
*pointer = "jellyfish"
|
||||
// creature through the pointer
|
||||
fmt.Println("*pointer =", *pointer) // *pointer = jellyfish
|
||||
// creature string
|
||||
fmt.Println("creature =", creature) // creature = jellyfish
|
||||
}
|
||||
3
Task/Copy-a-string/Groovy/copy-a-string-1.groovy
Normal file
3
Task/Copy-a-string/Groovy/copy-a-string-1.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def string = 'Scooby-doo-bee-doo' // assigns string object to a variable reference
|
||||
def stringRef = string // assigns another variable reference to the same object
|
||||
def stringCopy = new String(string) // copies string value into a new object, and assigns to a third variable reference
|
||||
4
Task/Copy-a-string/Groovy/copy-a-string-2.groovy
Normal file
4
Task/Copy-a-string/Groovy/copy-a-string-2.groovy
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
assert string == stringRef // they have equal values (like Java equals(), not like Java ==)
|
||||
assert string.is(stringRef) // they are references to the same objext (like Java ==)
|
||||
assert string == stringCopy // they have equal values
|
||||
assert ! string.is(stringCopy) // they are references to different objects (like Java !=)
|
||||
2
Task/Copy-a-string/Harbour/copy-a-string.harbour
Normal file
2
Task/Copy-a-string/Harbour/copy-a-string.harbour
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
cSource := "Hello World"
|
||||
cDestination := cSource
|
||||
2
Task/Copy-a-string/HicEst/copy-a-string.hicest
Normal file
2
Task/Copy-a-string/HicEst/copy-a-string.hicest
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src = "Hello World"
|
||||
dst = src
|
||||
10
Task/Copy-a-string/I/copy-a-string.i
Normal file
10
Task/Copy-a-string/I/copy-a-string.i
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
//Strings are immutable in 'i'.
|
||||
software {
|
||||
a = "Hello World"
|
||||
b = a //This copies the string.
|
||||
|
||||
a += "s"
|
||||
|
||||
print(a)
|
||||
print(b)
|
||||
}
|
||||
6
Task/Copy-a-string/Icon/copy-a-string.icon
Normal file
6
Task/Copy-a-string/Icon/copy-a-string.icon
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
procedure main()
|
||||
a := "qwerty"
|
||||
b := a
|
||||
b[2+:4] := "uarterl"
|
||||
write(a," -> ",b)
|
||||
end
|
||||
2
Task/Copy-a-string/J/copy-a-string.j
Normal file
2
Task/Copy-a-string/J/copy-a-string.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src =: 'hello'
|
||||
dest =: src
|
||||
7
Task/Copy-a-string/Java/copy-a-string-1.java
Normal file
7
Task/Copy-a-string/Java/copy-a-string-1.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
String src = "Hello";
|
||||
String newAlias = src;
|
||||
String strCopy = new String(src);
|
||||
|
||||
//"newAlias == src" is true
|
||||
//"strCopy == src" is false
|
||||
//"strCopy.equals(src)" is true
|
||||
1
Task/Copy-a-string/Java/copy-a-string-2.java
Normal file
1
Task/Copy-a-string/Java/copy-a-string-2.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
StringBuffer srcCopy = new StringBuffer("Hello");
|
||||
4
Task/Copy-a-string/JavaScript/copy-a-string-1.js
Normal file
4
Task/Copy-a-string/JavaScript/copy-a-string-1.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var container = {myString: "Hello"};
|
||||
var containerCopy = container; // Now both identifiers refer to the same object
|
||||
|
||||
containerCopy.myString = "Goodbye"; // container.myString will also return "Goodbye"
|
||||
4
Task/Copy-a-string/JavaScript/copy-a-string-2.js
Normal file
4
Task/Copy-a-string/JavaScript/copy-a-string-2.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var a = "Hello";
|
||||
var b = a; // Same as saying window.b = window.a
|
||||
|
||||
b = "Goodbye" // b contains a copy of a's value and a will still return "Hello"
|
||||
1
Task/Copy-a-string/Joy/copy-a-string.joy
Normal file
1
Task/Copy-a-string/Joy/copy-a-string.joy
Normal file
|
|
@ -0,0 +1 @@
|
|||
"hello" dup
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue