Anonymous user
Copy a string: Difference between revisions
add string copy for BLC
m (→{{header|C}}) |
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}}===
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="
MOVE src TO dst</syntaxhighlight>
Line 972 ⟶ 984:
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
a$ = "hello"
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
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|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|
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="
var t = s
System.print("Are 's' and 't' equal? %(s == t)")</syntaxhighlight>
|