Copy a string: Difference between revisions

Content added Content deleted
m (Spelling/grammar/aesthetics and removed an extra category tag)
Line 1: Line 1:
{{task}}
{{task}}
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.
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.


=={{header|Ada}}==
=={{header|Ada}}==
Line 104: Line 104:


=={{header|C sharp|C #}}==
=={{header|C sharp|C #}}==
[[Category:C sharp]]
string src = "Hello";
string src = "Hello";
string dst = src;
string dst = src;
Line 125: Line 124:
=={{header|Factor}}==
=={{header|Factor}}==


Factor strings are mutable but not growable. Strings will be immutable in a future release.
Factor strings are mutable but not growable. Strings will be immutable in a future release.


"This is a mutable string." dup ! reference
"This is a mutable string." dup ! reference
Line 140: Line 139:


SBUF" I'll be a string someday." >string .
SBUF" I'll be a string someday." >string .
"I'll be a string somday."
"I'll be a string someday."


=={{header|Forth}}==
=={{header|Forth}}==


Forth strings are generally stored in memory as prefix counted string, where the first byte contains the string length. However, on the stack they are most often represented as <addr cnt> pairs. Thus the way you copy a string depends on where the source string comes from:
Forth strings are generally stored in memory as prefix counted string, where the first byte contains the string length. However, on the stack they are most often represented as <addr cnt> pairs. Thus the way you copy a string depends on where the source string comes from:


\ Allocate two string buffers
\ Allocate two string buffers
Line 191: Line 190:
=={{header|Pop11}}==
=={{header|Pop11}}==


In Pop11 normal data are represented by references, so plain assignment
In Pop11 normal data are represented by references, so plain assignment will copy references. To copy data one has to use copy procedure:
will copy references. To copy data one has to use copy procedure:


vars src, dst;
vars src, dst;