www.digitalmars.com         C & C++   DMDScript  

D - String

reply "Don Stewart" <donald.m.stewart btinternet.com> writes:
Sorry if I havn't found this in the docs, but is there an equivalent to the
java String complex type in D ?

I see mention of toString in the topics, but cannot see under Types in the
documentation, a String class.
May 20 2002
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Don Stewart wrote:

 Sorry if I havn't found this in the docs, but is there an equivalent to the
 java String complex type in D ?

 I see mention of toString in the topics, but cannot see under Types in the
 documentation, a String class.

D uses arrays of chars. Arrays in D may be const-sized or dynamic (most string applications would use dynamic arrays, of course). Since the length is known by the length of the array, strings in D are not null-terminated. (there's one caveat: string constants include an unneceesary null terminator-doesn't count towards the length of the array-so that you can pass string constants directly into C functions that expect null terminators.) You can append an array to another with the concatenate operator. Since there are no null terminator, this also works perfectly for strings: char str[] = "asdf"; str ~= "jkl"; /* str now is "asdfjkl" */ http://digitalmars.com/d/arrays.html -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
May 21 2002
parent "Don Stewart" <donald.m.stewart btinternet.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3CEAB7F7.D58FD38A deming-os.org...
 Don Stewart wrote:

 Sorry if I havn't found this in the docs, but is there an equivalent to


 java String complex type in D ?

 I see mention of toString in the topics, but cannot see under Types in


 documentation, a String class.

D uses arrays of chars. Arrays in D may be const-sized or dynamic (most

 applications would use dynamic arrays, of course).

 Since the length is known by the length of the array, strings in D are not
 null-terminated.  (there's one caveat: string constants include an

 null terminator-doesn't count towards the length of the array-so that you

 pass string constants directly into C functions that expect null

 You can append an array to another with the concatenate operator.  Since

 are no null terminator, this also works perfectly for strings:

 char str[] = "asdf";
 str ~= "jkl";        /* str now is "asdfjkl" */

 http://digitalmars.com/d/arrays.html

 --
 The Villagers are Online! villagersonline.com

 .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
 .[ (a version.of(English).(precise.more)) is(possible) ]
 ?[ you want.to(help(develop(it))) ]

Many Thanks Russ
May 21 2002