Copy a string: Difference between revisions

Content deleted Content added
Root (talk | contribs)
→‎Pascal: fix non-standard example containing multiple mistakes
KayproKid (talk | contribs)
Added S-BASIC example
 
(11 intermediate revisions by 5 users not shown)
Line 575:
src$ = " world..."
PRINT dst$; src$</syntaxhighlight>
 
==={{header|SmallBASIC}}===
<syntaxhighlight lang="qbasic">
src = "Hello"
dst = src
src = " world..."
PRINT dst; src
</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 995 ⟶ 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,980 ⟶ 2,001:
writeStr(destination, source);
end.</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
Strings in PascalABC.NET are references.
<syntaxhighlight lang="pascal" highlight="9,13,15">
begin
var s: string := 'Hello';
var s1 := s;
end.
</syntaxhighlight>
 
=={{header|Perl}}==
Line 2,348 ⟶ 2,378:
end;
end;</syntaxhighlight>
 
=={{header|S-BASIC}}==
Creating a copy of a string requires only a simple assignment. The effect of a reference can be obtained by declaring a base-located string and positioning it at run-time on top of the original string, the address of which can be obtained using the LOCATION statement Since they occupy the same memory, any change to the original string will be reflected in the base-located string and vice-versa.
<syntaxhighlight lang = "BASIC">
var original, copy = string
based referenced = string
var strloc = integer
 
rem - position referenced string on top of original string
location var strloc = original
base referenced at strloc
 
original = "Hello, World"
copy = original
 
print "Original : ", original
print "Copy : ", copy
print "Referenced: ", referenced
print
 
original = "Goodbye, World"
 
print "Original : ", original rem - changed
print "Copy : ", copy rem - unchanged
print "Referenced: ", referenced rem - changed
 
end
</syntaxhighlight>
{{out}}
<pre>
Original : Hello, World
Copy : Hello, World
Referenced: Hello, World
 
Original : Goodbye, World
Copy : Hello, World
Referenced: Goodbye, World
</pre>
 
=={{header|Scala}}==