Copy a string: Difference between revisions

Add ed example
(add lambdatalk)
(Add ed example)
 
(9 intermediate revisions by 9 users not shown)
Line 575:
src$ = " world..."
PRINT dst$; src$</syntaxhighlight>
 
==={{header|SmallBASIC}}===
<syntaxhighlight lang="pascalqbasic">program in,out;
src = "Hello"
dst = src
src = " world..."
PRINT dst; src
end;</syntaxhighlight>
 
 
==={{header|True BASIC}}===
Line 636 ⟶ 645:
?(^same$+5) = ?(^source$+5)
PRINT same$</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
 
In BLC, every value is immutable, including byte-strings. So one never needs to copy them; references are shared.
 
=={{header|BQN}}==
Line 822 ⟶ 835:
=={{header|COBOL}}==
{{trans|C#}}
<syntaxhighlight lang="cobolcobolfree">MOVE "Hello" TO src
MOVE src TO dst</syntaxhighlight>
 
Line 980 ⟶ 993:
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">a$ = "hello"
a$ = "hello"
b$ = a$</syntaxhighlight>
b$ = a$
print b$
b$ = a$</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 992 ⟶ 1,008:
t → "abc"
(eq? s t) → #t ;; same reference, same object
</syntaxhighlight>
 
=={{header|Ed}}==
 
Copies the current buffer contents in its entirety.
 
<syntaxhighlight>
,t
</syntaxhighlight>
 
Line 1,960 ⟶ 1,984:
 
=={{header|Pascal}}==
''See also: [[#Delphi|Delphi]]''
<syntaxhighlight lang="pascal" highlight="9,13,15">program copyAString;
var
{ The Extended Pascal `string` schema data type
is essentially a `packed array[1..capacity] of char`. }
source, destination: string(80);
begin
source := 'Hello world!';
{ In Pascal _whole_ array data type values can be copied by assignment. }
destination := source;
{ Provided `source` is a _non-empty_ string value
you can copy in Extended Pascal sub-ranges _of_ _string_ types, too.
Note, the sub-range notation is not permitted for a `bindable` data type. }
destination := source[1..length(source)];
{ You can also employ Extended Pascal’s `writeStr` routine: }
writeStr(destination, source);
end.</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="pascal">program in,out;
Strings in PascalABC.NET are references.
 
<syntaxhighlight lang="pascal" highlight="9,13,15">
type
pString = ^string;
 
var
 
s1,s2 : string ;
pStr : pString ;
 
begin
var s1,s2 s: string := 'Hello';
 
var /*s1 direct:= copy */s;
end.
s1 := 'Now is the time for all good men to come to the aid of their party.'
</syntaxhighlight>
s2 := s1 ;
 
writeln(s1);
writeln(s2);
 
/* By Reference */
pStr := @s1 ;
writeln(pStr^);
 
pStr := @s2 ;
writeln(pStr^);
 
end;</syntaxhighlight>
 
=={{header|Perl}}==
Line 2,306 ⟶ 2,327:
</syntaxhighlight>
 
=={{header|RPL}}==
Copy a string in stack:
DUP
Copy a string from one variable to another:
"Example" 'STR1' STO
STR1 'STR2' STO
=={{header|Ruby}}==
In Ruby, String are mutable.
Line 2,610 ⟶ 2,637:
<syntaxhighlight lang="vbnet">Dim a As String = "Test String"
Dim b As String = String.Copy(a) ' New string</syntaxhighlight>
 
=={{header|V (Vlang)}}==
Strings in Vlang are immutable. There is no need to distinguish between copying and making an additional reference.
<syntaxhighlight lang="Vlang">
text := "Hello"
copy_of := text
println(copy_of)
</syntaxhighlight>
 
{{out}}
<pre>
Hello
</pre>
 
=={{header|Wren}}==
Line 2,615 ⟶ 2,655:
 
Although technically a reference type, this means there is no need to distinguish between copying the contents of a string and making an additional reference. We can therefore just use assignment to copy a string.
<syntaxhighlight lang="ecmascriptwren">var s = "wren"
var t = s
System.print("Are 's' and 't' equal? %(s == t)")</syntaxhighlight>
86

edits