To dup or not to dup?
Jürgen Herz
juergen at jherz.redirectme.net
Sun Feb 25 12:55:01 PST 2007
Hi,
I'm absolutely new to D and about to see if D is a language I could like.
On http://www.digitalmars.com/d/cppstrings.html I found
char[] s1 = "hello world";
char[] s2 = "goodbye ".dup;
s2[8..13] = s1[6..11]; // s2 is "goodbye world"
The .dup is needed because string literals are read-only in D, the .dup
will create a copy that is writable.
The same with
char []a = "Txst";
a[1] = 'a';
I find that interesting because here it also works (compiles and runs)
without .dup (DMD 1.007). Has the language changed since writing that
web page?
Jürgen
More information about the Digitalmars-d
mailing list