Copy a string: Difference between revisions

add string copy for BLC
imported>Tromp
(add string copy for BLC)
 
(11 intermediate revisions by 10 users not shown)
Line 636:
?(^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 751 ⟶ 755:
}</syntaxhighlight>
 
==={{libheader|Gadget}}===
<pre>
 
Versión 2, using Gadget library</pre>
Versión 2, using Gadget library.
 
Link:
 
https://github.com/DanielStuardo/Gadget
 
 
<syntaxhighlight lang="c">
Line 781 ⟶ 791:
</syntaxhighlight>
{{out}}
<pre>
v = Hello world!
w = this message is a message
Line 789 ⟶ 800:
v = THIS MESSAGE IS A PROOF
w = this message is a message
</pre>
 
=={{header|C sharp|C#}}==
Line 814 ⟶ 826:
=={{header|COBOL}}==
{{trans|C#}}
<syntaxhighlight lang="cobolcobolfree">MOVE "Hello" TO src
MOVE src TO dst</syntaxhighlight>
 
Line 972 ⟶ 984:
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">a$ = "hello"
a$ = "hello"
b$ = a$</syntaxhighlight>
b$ = a$
print b$
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 1,074 ⟶ 1,089:
(equal str1 str1-ref) ;=> t
(equal str1 str2)) ;=> t</syntaxhighlight>
 
=={{header|EMal}}==
in EMal strings are mutable
<syntaxhighlight lang="emal">
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?"
|^
</syntaxhighlight>
 
=={{header|Erlang}}==
Line 1,417 ⟶ 1,448:
In LabVIEW, one can simply wire an input to more than one output.<br/>
{{VI snippet}}<br/>[[File:LabVIEW_Copy_a_string.png]]
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def S1 hello world} // set S1 to "hello world"
-> S1
{S1} // get the value of S1
-> hello world
 
{def S2 S1} // define S2 as S1
-> S2
{S2} // the value of S2 is S1
-> S1
{{S2}} // get the value of the value of S2
-> hello world
 
{def S3 {S1}} // set S3 to the value of S1
-> S3
{S3} // get the value of S3
-> hello world
</syntaxhighlight>
 
=={{header|Lang5}}==
Line 1,916 ⟶ 1,967:
 
=={{header|Pascal}}==
''See also: [[#Delphi|Delphi]]''
 
<syntaxhighlight lang="pascal" highlight="9,13,15">program in,outcopyAString;
var
 
{ The Extended Pascal `string` schema data type
type
is essentially a `packed array[1..capacity] of char`. }
source, destination: string(80);
pString = ^string;
begin
 
source := 'Hello world!';
var
{ In Pascal _whole_ array data type values can be copied by assignment. }
 
destination := source;
s1,s2 : string ;
{ Provided `source` is a _non-empty_ string value
pStr : pString ;
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. }
begin
destination := source[1..length(source)];
 
{ You can also employ Extended Pascal’s `writeStr` routine: }
/* direct copy */
writeStr(destination, source);
s1 := 'Now is the time for all good men to come to the aid of their party.'
end.</syntaxhighlight>
s2 := s1 ;
 
writeln(s1);
writeln(s2);
 
/* By Reference */
pStr := @s1 ;
writeln(pStr^);
 
pStr := @s2 ;
writeln(pStr^);
 
end;</syntaxhighlight>
 
=={{header|Perl}}==
Line 2,262 ⟶ 2,301:
</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,326 ⟶ 2,371:
<syntaxhighlight lang="scheme">(define dst (string-copy src))</syntaxhighlight>
 
=={{header|Seed7sed}}==
In ''sed'', there are two distinct locations for storing a string: The "pattern space" and the "hold space". The <code>h</code> command copies pattern space to hold space. The <code>g</code> command copies hold space to pattern space.
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">var string: dest is "";
 
Line 2,564 ⟶ 2,611:
<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,569 ⟶ 2,629:
 
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>
Anonymous user