digitalmars.D - string init
- kevinbealer yahoo.com (8/8) May 03 2004 Let's say I want to define a mutable string:
- Andy Friesen (3/18) May 03 2004 char[] a = ("abcd").dup; may work for you.
- Kevin Bealer (3/21) May 04 2004 Yep, that looks like the most logical.
- Ben Hinkle (3/16) May 03 2004 The ".dup" property will duplicate an array:
- Mike Wynn (53/61) May 06 2004 try const .... as in
Let's say I want to define a mutable string: char[] a_tmp = "abcd"; // immutable ref char[] a; a[] = a_tmp; // mutable copy of immutable data. OR..? char[] a = "abc" ~ "d"; Is there a simpler or more direct syntax? Kevin
May 03 2004
kevinbealer yahoo.com wrote:Let's say I want to define a mutable string: char[] a_tmp = "abcd"; // immutable ref char[] a; a[] = a_tmp; // mutable copy of immutable data. OR..? char[] a = "abc" ~ "d"; Is there a simpler or more direct syntax? Kevinchar[] a = ("abcd").dup; may work for you. -- andy
May 03 2004
In article <c76g4e$iau$1 digitaldaemon.com>, Andy Friesen says...kevinbealer yahoo.com wrote:Yep, that looks like the most logical. KevinLet's say I want to define a mutable string: char[] a_tmp = "abcd"; // immutable ref char[] a; a[] = a_tmp; // mutable copy of immutable data. OR..? char[] a = "abc" ~ "d"; Is there a simpler or more direct syntax? Kevinchar[] a = ("abcd").dup; may work for you. -- andy
May 04 2004
kevinbealer yahoo.com wrote:Let's say I want to define a mutable string: char[] a_tmp = "abcd"; // immutable ref char[] a; a[] = a_tmp; // mutable copy of immutable data. OR..? char[] a = "abc" ~ "d"; Is there a simpler or more direct syntax? KevinThe ".dup" property will duplicate an array: char[] a = a_tmp.dup;
May 03 2004
On Mon, 3 May 2004 22:05:57 +0000 (UTC), kevinbealer yahoo.com wrote:Let's say I want to define a mutable string: char[] a_tmp = "abcd"; // immutable ref char[] a; a[] = a_tmp; // mutable copy of immutable data. OR..? char[] a = "abc" ~ "d"; Is there a simpler or more direct syntax? Kevintry const .... as in --------------------- import std.c.stdio; void nctest() { char[] a = "abcd"; char[]b = a; printf( "char[] a = 'acbd'\n" ); printf( "char[] b = a;\n=>\n" ); printf( "a=%.*s\n", a ); printf( "b=%.*s\n", b ); printf( "b[2]='2'...\n" ); b[2] = '2'; printf( "a=%.*s\n", a ); printf( "b=%.*s\n", b ); } void ctest() { const char[] a = "abcd"; char[]b = a; printf( "const char[] a = 'acbd'\n" ); printf( "char[] b = a;\n=>\n" ); printf( "b[2]='2'...\n" ); printf( "a=%.*s\n", a ); printf( "b=%.*s\n", b ); printf( "b[2]='2'...\n" ); b[2] = '2'; printf( "a=%.*s\n", a ); printf( "b=%.*s\n", b ); } int main( char[][] args ) { nctest(); ctest(); return 0; } ------------------------ output (as one would hope is) char[] a = 'acbd' char[] b = a; => a=abcd b=abcd b[2]='2'... a=ab2d b=ab2d const char[] a = 'acbd' char[] b = a; => b[2]='2'... a=abcd b=abcd b[2]='2'... a=abcd b=ab2d
May 06 2004