tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
1
Task/Copy-a-string/0DESCRIPTION
Normal file
1
Task/Copy-a-string/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
This task is about copying a string. Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string.
|
||||
4
Task/Copy-a-string/1META.yaml
Normal file
4
Task/Copy-a-string/1META.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
note: Basic language learning
|
||||
3
Task/Copy-a-string/ABAP/copy-a-string.abap
Normal file
3
Task/Copy-a-string/ABAP/copy-a-string.abap
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
data: lv_string1 type string value 'Test',
|
||||
lv_string2 type string.
|
||||
lv_string2 = lv_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
|
||||
)
|
||||
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...
|
||||
}
|
||||
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;
|
||||
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
|
||||
11
Task/Copy-a-string/BBC-BASIC/copy-a-string.bbc
Normal file
11
Task/Copy-a-string/BBC-BASIC/copy-a-string.bbc
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$
|
||||
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 }
|
||||
13
Task/Copy-a-string/C++/copy-a-string.cpp
Normal file
13
Task/Copy-a-string/C++/copy-a-string.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
int main( ) {
|
||||
std::string original ( "This is the original" ) ;
|
||||
std::string mycopy( original.length( ) , ' ' ) ;
|
||||
std::copy ( original.begin( ) , original.end( ) , mycopy.begin( ) ) ;
|
||||
std::cout << "This is the copy: " << mycopy << std::endl ;
|
||||
original.assign( "Now we change the original! " ) ;
|
||||
std::cout << "mycopy still is " << mycopy << std::endl ;
|
||||
return 0 ;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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 />
|
||||
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!!!!!"
|
||||
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;
|
||||
}
|
||||
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/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
|
||||
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
|
||||
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
|
||||
4
Task/Copy-a-string/Gambas/copy-a-string.gambas
Normal file
4
Task/Copy-a-string/Gambas/copy-a-string.gambas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
DIM src AS String
|
||||
DIM dst AS String
|
||||
src = "Hello"
|
||||
dst = src
|
||||
2
Task/Copy-a-string/Go/copy-a-string.go
Normal file
2
Task/Copy-a-string/Go/copy-a-string.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src := "Hello"
|
||||
dst := src
|
||||
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/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
|
||||
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
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Var:String str1 = "Hello";
|
||||
Var:String str2 = str1;
|
||||
1
Task/Copy-a-string/Lang5/copy-a-string.lang5
Normal file
1
Task/Copy-a-string/Lang5/copy-a-string.lang5
Normal file
|
|
@ -0,0 +1 @@
|
|||
'hello dup
|
||||
4
Task/Copy-a-string/Liberty-BASIC/copy-a-string.liberty
Normal file
4
Task/Copy-a-string/Liberty-BASIC/copy-a-string.liberty
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
src$ = "Hello"
|
||||
dest$ = src$
|
||||
print src$
|
||||
print dest$
|
||||
9
Task/Copy-a-string/Lisaac/copy-a-string.lisaac
Normal file
9
Task/Copy-a-string/Lisaac/copy-a-string.lisaac
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
+ scon : STRING_CONSTANT;
|
||||
+ svar : STRING;
|
||||
|
||||
scon := "sample";
|
||||
svar := STRING.create 20;
|
||||
svar.copy scon;
|
||||
svar.append "!\n";
|
||||
|
||||
svar.print;
|
||||
10
Task/Copy-a-string/Logo/copy-a-string.logo
Normal file
10
Task/Copy-a-string/Logo/copy-a-string.logo
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
make "a "foo
|
||||
make "b "foo
|
||||
print .eq :a :b ; true, identical symbols are reused
|
||||
|
||||
make "c :a
|
||||
print .eq :a :c ; true, copy a reference
|
||||
|
||||
make "c word :b "|| ; force a copy of the contents of a word by appending the empty word
|
||||
print equal? :b :c ; true
|
||||
print .eq :b :c ; false
|
||||
4
Task/Copy-a-string/Lua/copy-a-string.lua
Normal file
4
Task/Copy-a-string/Lua/copy-a-string.lua
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
a = "string"
|
||||
b = a
|
||||
print(a == b) -->true
|
||||
print(b) -->string
|
||||
2
Task/Copy-a-string/MATLAB/copy-a-string.m
Normal file
2
Task/Copy-a-string/MATLAB/copy-a-string.m
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
string1 = 'Hello';
|
||||
string2 = string1;
|
||||
2
Task/Copy-a-string/MAXScript/copy-a-string.maxscript
Normal file
2
Task/Copy-a-string/MAXScript/copy-a-string.maxscript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
str1 = "Hello"
|
||||
str2 = copy str1
|
||||
2
Task/Copy-a-string/MUMPS/copy-a-string.mumps
Normal file
2
Task/Copy-a-string/MUMPS/copy-a-string.mumps
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
SET S1="Greetings, Planet"
|
||||
SET S2=S1
|
||||
13
Task/Copy-a-string/Maple/copy-a-string.maple
Normal file
13
Task/Copy-a-string/Maple/copy-a-string.maple
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
> s := "some string";
|
||||
s := "some string"
|
||||
|
||||
> t := "some string";
|
||||
t := "some string"
|
||||
|
||||
> evalb( s = t ); # they are equal
|
||||
true
|
||||
|
||||
> addressof( s ) = addressof( t ); # not just equal data, but the same address in memory
|
||||
3078334210 = 3078334210
|
||||
|
||||
> u := t: # copy reference
|
||||
2
Task/Copy-a-string/Mathematica/copy-a-string.math
Normal file
2
Task/Copy-a-string/Mathematica/copy-a-string.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a="Hello World"
|
||||
b=a
|
||||
19
Task/Copy-a-string/Maxima/copy-a-string.maxima
Normal file
19
Task/Copy-a-string/Maxima/copy-a-string.maxima
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* It's possible in Maxima to access individual characters by subscripts, but it's not the usual way.
|
||||
Also, the result is "Lisp character", which cannot be used by other Maxima functions except cunlisp. The usual
|
||||
way to access characters is charat, returning a "Maxima character" (actually a one characte string). With the latter,
|
||||
it's impossible to modify a string in place, thus scopy is of little use. */
|
||||
|
||||
a: "loners"$
|
||||
b: scopy(a)$
|
||||
c: a$
|
||||
|
||||
c[2]: c[5]$
|
||||
|
||||
a;
|
||||
"losers"
|
||||
|
||||
b;
|
||||
"loners"
|
||||
|
||||
c;
|
||||
"losers"
|
||||
7
Task/Copy-a-string/Metafont/copy-a-string.metafont
Normal file
7
Task/Copy-a-string/Metafont/copy-a-string.metafont
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
string s, a;
|
||||
s := "hello";
|
||||
a := s;
|
||||
s := s & " world";
|
||||
message s; % writes "hello world"
|
||||
message a; % writes "hello"
|
||||
end
|
||||
8
Task/Copy-a-string/Mirah/copy-a-string.mirah
Normal file
8
Task/Copy-a-string/Mirah/copy-a-string.mirah
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
src = "Hello"
|
||||
new_alias = src
|
||||
|
||||
puts 'interned strings are equal' if src == new_alias
|
||||
|
||||
str_copy = String.new(src)
|
||||
puts 'non-interned strings are not equal' if str_copy != src
|
||||
puts 'compare strings with equals()' if str_copy.equals(src)
|
||||
2
Task/Copy-a-string/Modula-3/copy-a-string.mod3
Normal file
2
Task/Copy-a-string/Modula-3/copy-a-string.mod3
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
VAR src: TEXT := "Foo";
|
||||
VAR dst: TEXT := src;
|
||||
18
Task/Copy-a-string/Nemerle/copy-a-string.nemerle
Normal file
18
Task/Copy-a-string/Nemerle/copy-a-string.nemerle
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Console;
|
||||
using Nemerle;
|
||||
|
||||
module StrCopy
|
||||
{
|
||||
Main() : void
|
||||
{
|
||||
mutable str1 = "I am not changed"; // str1 is bound to literal
|
||||
def str2 = lazy(str1); // str2 will be bound when evaluated
|
||||
def str3 = str1; // str3 is bound to value of str1
|
||||
str1 = "I am changed"; // str1 is bound to new literal
|
||||
Write($"$(str1)\n$(str2)\n$(str3)\n"); // str2 is bound to value of str1
|
||||
// Output: I am changed
|
||||
// I am changed
|
||||
// I am not changed
|
||||
}
|
||||
}
|
||||
10
Task/Copy-a-string/NetRexx/copy-a-string.netrexx
Normal file
10
Task/Copy-a-string/NetRexx/copy-a-string.netrexx
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
s1 = 'This is a Rexx string'
|
||||
s2 = s1
|
||||
|
||||
s2 = s2.changestr(' ', '_')
|
||||
|
||||
say s1
|
||||
say s2
|
||||
6
Task/Copy-a-string/NewLISP/copy-a-string.newlisp
Normal file
6
Task/Copy-a-string/NewLISP/copy-a-string.newlisp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(define (assert f msg) (if (not f) (println msg)))
|
||||
|
||||
(setq s "Greetings!" c (copy s))
|
||||
(reverse c) ; Modifies c in place.
|
||||
|
||||
(assert (= s c) "Strings not equal.")
|
||||
1
Task/Copy-a-string/OCaml/copy-a-string.ocaml
Normal file
1
Task/Copy-a-string/OCaml/copy-a-string.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let dst = String.copy src
|
||||
10
Task/Copy-a-string/Oberon-2/copy-a-string.oberon-2
Normal file
10
Task/Copy-a-string/Oberon-2/copy-a-string.oberon-2
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
MODULE CopyString;
|
||||
TYPE
|
||||
String = ARRAY 128 OF CHAR;
|
||||
VAR
|
||||
a,b: String;
|
||||
|
||||
BEGIN
|
||||
a := "plain string";
|
||||
COPY(a,b);
|
||||
END CopyString.
|
||||
2
Task/Copy-a-string/Objeck/copy-a-string.objeck
Normal file
2
Task/Copy-a-string/Objeck/copy-a-string.objeck
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a := "GoodBye!";
|
||||
b := a;
|
||||
4
Task/Copy-a-string/Objective-C/copy-a-string-1.m
Normal file
4
Task/Copy-a-string/Objective-C/copy-a-string-1.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
NSString *original = @"Literal String";
|
||||
NSString *new = [original copy];
|
||||
NSString *anotherNew = [NSString stringWithString:original];
|
||||
NSString *newMutable = [original mutableCopy];
|
||||
4
Task/Copy-a-string/Objective-C/copy-a-string-2.m
Normal file
4
Task/Copy-a-string/Objective-C/copy-a-string-2.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
NSMutableString *original = [NSMutableString stringWithString:@"Literal String"];
|
||||
NSString *immutable = [original copy];
|
||||
NSString *anotherImmutable = [NSString stringWithString:original];
|
||||
NSMutableString *mutable = [original mutableCopy];
|
||||
2
Task/Copy-a-string/Objective-C/copy-a-string-3.m
Normal file
2
Task/Copy-a-string/Objective-C/copy-a-string-3.m
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
const char *cstring = "I'm a plain C string";
|
||||
NSString *string = [NSString stringWithUTF8String:cstring];
|
||||
2
Task/Copy-a-string/Objective-C/copy-a-string-4.m
Normal file
2
Task/Copy-a-string/Objective-C/copy-a-string-4.m
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
char bytes[] = "some data";
|
||||
NSString *string = [[NSString alloc] initWithBytes:bytes length:9 encoding:NSASCIIStringEncoding];
|
||||
1
Task/Copy-a-string/Octave/copy-a-string.octave
Normal file
1
Task/Copy-a-string/Octave/copy-a-string.octave
Normal file
|
|
@ -0,0 +1 @@
|
|||
str2 = str1
|
||||
2
Task/Copy-a-string/OxygenBasic/copy-a-string.oxy
Normal file
2
Task/Copy-a-string/OxygenBasic/copy-a-string.oxy
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
string s, t="hello"
|
||||
s=t
|
||||
1
Task/Copy-a-string/PARI-GP/copy-a-string-1.pari
Normal file
1
Task/Copy-a-string/PARI-GP/copy-a-string-1.pari
Normal file
|
|
@ -0,0 +1 @@
|
|||
s1=s
|
||||
2
Task/Copy-a-string/PARI-GP/copy-a-string-2.pari
Normal file
2
Task/Copy-a-string/PARI-GP/copy-a-string-2.pari
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
GEN string_copy = gcopy(string);
|
||||
GEN string_ref = string;
|
||||
2
Task/Copy-a-string/PHP/copy-a-string.php
Normal file
2
Task/Copy-a-string/PHP/copy-a-string.php
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$src = "Hello";
|
||||
$dst = $src;
|
||||
3
Task/Copy-a-string/PL-I/copy-a-string.pli
Normal file
3
Task/Copy-a-string/PL-I/copy-a-string.pli
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
declare (s1, s2) character (20) varying;
|
||||
s1 = 'now is the time';
|
||||
s2 = s1;
|
||||
28
Task/Copy-a-string/Pascal/copy-a-string.pascal
Normal file
28
Task/Copy-a-string/Pascal/copy-a-string.pascal
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
program in,out;
|
||||
|
||||
type
|
||||
|
||||
pString = ^string;
|
||||
|
||||
var
|
||||
|
||||
s1,s2 : string ;
|
||||
pStr : pString ;
|
||||
|
||||
begin
|
||||
|
||||
/* direct copy */
|
||||
s1 := 'Now is the time for all good men to come to the aid of their party.'
|
||||
s2 := s1 ;
|
||||
|
||||
writeln(s1);
|
||||
writeln(s2);
|
||||
|
||||
/* By Reference */
|
||||
pStr := @s1 ;
|
||||
writeln(pStr^);
|
||||
|
||||
pStr := @s2 ;
|
||||
writeln(pStr^);
|
||||
|
||||
end;
|
||||
6
Task/Copy-a-string/Perl-6/copy-a-string-1.pl6
Normal file
6
Task/Copy-a-string/Perl-6/copy-a-string-1.pl6
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
my $original = 'Hello.';
|
||||
my $copy = $original;
|
||||
say $copy; # prints "Hello."
|
||||
$copy = 'Goodbye.';
|
||||
say $copy; # prints "Goodbye."
|
||||
say $original; # prints "Hello."
|
||||
6
Task/Copy-a-string/Perl-6/copy-a-string-2.pl6
Normal file
6
Task/Copy-a-string/Perl-6/copy-a-string-2.pl6
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
my $original = 'Hello.';
|
||||
my $bound := $original;
|
||||
say $bound; # prints "Hello."
|
||||
$bound = 'Goodbye.';
|
||||
say $bound; # prints "Goodbye."
|
||||
say $original; # prints "Goodbye."
|
||||
12
Task/Copy-a-string/Perl-6/copy-a-string-3.pl6
Normal file
12
Task/Copy-a-string/Perl-6/copy-a-string-3.pl6
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
my $original = 'Hello.';
|
||||
my $bound-ro ::= $original;
|
||||
say $bound-ro; # prints "Hello."
|
||||
try {
|
||||
$bound-ro = 'Runtime error!';
|
||||
CATCH {
|
||||
say "$!"; # prints "Cannot modify readonly value"
|
||||
};
|
||||
};
|
||||
say $bound-ro; # prints "Hello."
|
||||
$original = 'Goodbye.';
|
||||
say $bound-ro; # prints "Goodbye."
|
||||
4
Task/Copy-a-string/Perl/copy-a-string-1.pl
Normal file
4
Task/Copy-a-string/Perl/copy-a-string-1.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
my $original = 'Hello.';
|
||||
my $new = $original;
|
||||
$new = 'Goodbye.';
|
||||
print "$original\n"; # prints "Hello."
|
||||
4
Task/Copy-a-string/Perl/copy-a-string-2.pl
Normal file
4
Task/Copy-a-string/Perl/copy-a-string-2.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
my $original = 'Hello.';
|
||||
my $ref = \$original;
|
||||
$$ref = 'Goodbye.';
|
||||
print "$original\n"; # prints "Goodbye."
|
||||
5
Task/Copy-a-string/Perl/copy-a-string-3.pl
Normal file
5
Task/Copy-a-string/Perl/copy-a-string-3.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
my $original = 'Hello.';
|
||||
our $alias;
|
||||
local *alias = \$original;
|
||||
$alias = 'Good evening.';
|
||||
print "$original\n"; # prints "Good evening."
|
||||
6
Task/Copy-a-string/Perl/copy-a-string-4.pl
Normal file
6
Task/Copy-a-string/Perl/copy-a-string-4.pl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use Lexical::Alias;
|
||||
my $original = 'Hello.';
|
||||
my $alias;
|
||||
alias $alias, $original;
|
||||
$alias = 'Good evening.';
|
||||
print "$original\n"; # prints "Good evening."
|
||||
3
Task/Copy-a-string/PicoLisp/copy-a-string.l
Normal file
3
Task/Copy-a-string/PicoLisp/copy-a-string.l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(setq Str1 "abcdef")
|
||||
(setq Str2 Str1) # Create a reference to that symbol
|
||||
(setq Str3 (name Str1)) # Create new symbol with name "abcdef"
|
||||
4
Task/Copy-a-string/Pike/copy-a-string.pike
Normal file
4
Task/Copy-a-string/Pike/copy-a-string.pike
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
int main(){
|
||||
string hi = "Hello World.";
|
||||
string ih = hi;
|
||||
}
|
||||
3
Task/Copy-a-string/Pop11/copy-a-string-1.pop11
Normal file
3
Task/Copy-a-string/Pop11/copy-a-string-1.pop11
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
vars src, dst;
|
||||
'Hello' -> src;
|
||||
copy(src) -> dst;
|
||||
2
Task/Copy-a-string/Pop11/copy-a-string-2.pop11
Normal file
2
Task/Copy-a-string/Pop11/copy-a-string-2.pop11
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
vars src='Hello';
|
||||
vars dst=copy(src);
|
||||
1
Task/Copy-a-string/PostScript/copy-a-string.ps
Normal file
1
Task/Copy-a-string/PostScript/copy-a-string.ps
Normal file
|
|
@ -0,0 +1 @@
|
|||
(hello) dup length string copy
|
||||
2
Task/Copy-a-string/PowerShell/copy-a-string-1.psh
Normal file
2
Task/Copy-a-string/PowerShell/copy-a-string-1.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$str = "foo"
|
||||
$dup = $str
|
||||
1
Task/Copy-a-string/PowerShell/copy-a-string-2.psh
Normal file
1
Task/Copy-a-string/PowerShell/copy-a-string-2.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
$dup = $str.Clone()
|
||||
4
Task/Copy-a-string/ProDOS/copy-a-string.dos
Normal file
4
Task/Copy-a-string/ProDOS/copy-a-string.dos
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
editvar /newvar /value=a /userinput=1 /title=Enter a string to be copied:
|
||||
editvar /newvar /value=b /userinput=1 /title=Enter current directory of the string:
|
||||
editvar /newvar /value=c /userinput=1 /title=Enter file to copy to:
|
||||
copy -a- from -b- to -c-
|
||||
2
Task/Copy-a-string/PureBasic/copy-a-string.purebasic
Normal file
2
Task/Copy-a-string/PureBasic/copy-a-string.purebasic
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src$ = "Hello"
|
||||
dst$ = src$
|
||||
8
Task/Copy-a-string/Python/copy-a-string-1.py
Normal file
8
Task/Copy-a-string/Python/copy-a-string-1.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
>>> src = "hello"
|
||||
>>> a = src
|
||||
>>> b = src[:]
|
||||
>>> import copy
|
||||
>>> c = copy.copy(src)
|
||||
>>> d = copy.deepcopy(src)
|
||||
>>> src is a is b is c is d
|
||||
True
|
||||
6
Task/Copy-a-string/Python/copy-a-string-2.py
Normal file
6
Task/Copy-a-string/Python/copy-a-string-2.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
>>> a = 'hello'
|
||||
>>> b = ''.join(a)
|
||||
>>> a == b
|
||||
True
|
||||
>>> b is a ### Might be True ... depends on "interning" implementation details!
|
||||
False
|
||||
2
Task/Copy-a-string/R/copy-a-string.r
Normal file
2
Task/Copy-a-string/R/copy-a-string.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
str1 <- "abc"
|
||||
str2 <- str1
|
||||
23
Task/Copy-a-string/REBOL/copy-a-string.rebol
Normal file
23
Task/Copy-a-string/REBOL/copy-a-string.rebol
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
REBOL [
|
||||
Title: "String Copy"
|
||||
Date: 2009-12-16
|
||||
Author: oofoe
|
||||
URL: http://rosettacode.org/wiki/Copy_a_string
|
||||
]
|
||||
|
||||
x: y: "Testing."
|
||||
y/2: #"X"
|
||||
print ["Both variables reference same string:" mold x "," mold y]
|
||||
|
||||
x: "Slackeriffic!"
|
||||
print ["Now reference different strings:" mold x "," mold y]
|
||||
|
||||
y: copy x ; String copy here!
|
||||
y/3: #"X" ; Modify string.
|
||||
print ["x copied to y, then modified:" mold x "," mold y]
|
||||
|
||||
y: copy/part x 7 ; Copy only the first part of y to x.
|
||||
print ["Partial copy:" mold x "," mold y]
|
||||
|
||||
y: copy/part skip x 2 3
|
||||
print ["Partial copy from offset:" mold x "," mold y]
|
||||
2
Task/Copy-a-string/REXX/copy-a-string.rexx
Normal file
2
Task/Copy-a-string/REXX/copy-a-string.rexx
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
src = "this is a string"
|
||||
dst = src
|
||||
4
Task/Copy-a-string/RLaB/copy-a-string.rlab
Normal file
4
Task/Copy-a-string/RLaB/copy-a-string.rlab
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
>> s1 = "A string"
|
||||
A string
|
||||
>> s2 = s1
|
||||
A string
|
||||
2
Task/Copy-a-string/Raven/copy-a-string-1.raven
Normal file
2
Task/Copy-a-string/Raven/copy-a-string-1.raven
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
'abc' as a
|
||||
a as b
|
||||
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