www.digitalmars.com         C & C++   DMDScript  

D - string documentation wrong?

reply "Sarat Venugopal" <sarat_ng n0spam.huelix.com> writes:
The docs say:

Strings can be copied, compared, concatenated, and appended:
char[] str;

char[] str1 = "abc";

str1 = str2;

if (str1 < str3) ...

func(str3 + str4);

str4 += str1;

with the obvious semantics.

It errors out with "Array operations not implemented". I see that
concatenantion is supported by ~. Am I missing something here?

Cheers,

Sarat
Oct 07 2003
next sibling parent davepermen <davepermen_member pathlink.com> writes:
as you say, suported with ~.. so use ~instead of +

func(string3 ~ string4);

string3 ~= string4;

and similar..

not sure about the <, i have to read that up again, haven't used it yet..
In article <blv327$15gn$1 digitaldaemon.com>, Sarat Venugopal says...
The docs say:

Strings can be copied, compared, concatenated, and appended:
char[] str;

char[] str1 = "abc";

str1 = str2;

if (str1 < str3) ...

func(str3 + str4);

str4 += str1;

with the obvious semantics.

It errors out with "Array operations not implemented". I see that
concatenantion is supported by ~. Am I missing something here?

Cheers,

Sarat

Oct 07 2003
prev sibling next sibling parent Charles Hixson <charleshixsn earthlink.net> writes:
Sarat Venugopal wrote:
 The docs say:
 
 Strings can be copied, compared, concatenated, and appended:
 char[] str;
 
 char[] str1 = "abc";
 
 str1 = str2;
 
 if (str1 < str3) ...
 
 func(str3 + str4);
 
 str4 += str1;
 
 with the obvious semantics.
 ...

Two comments: 1) do be aware that D is still a work in progress. I'm never certain before I try just which language features have actually been implemented. 2) shouldn't that be str4 ~= str1 rather than str4 += str1 ? 2a) if you're missing a feature, you might be able to implement it yourself in a subclass via redefining the operation. (I admit I haven't tried this with the "array of chars" type. But for some other's it's worked well.... I say without having gotten the application to the point where I can do unit testing.)
Oct 07 2003
prev sibling next sibling parent J C Calvarese <jcc7 cox.net> writes:
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Sarat Venugopal wrote:
 The docs say:
 
 Strings can be copied, compared, concatenated, and appended:
 char[] str;
 
 char[] str1 = "abc";
 
 str1 = str2;
 
 if (str1 < str3) ...
 
 func(str3 + str4);
 
 str4 += str1;
 
 with the obvious semantics.
 
 It errors out with "Array operations not implemented". I see that
 concatenantion is supported by ~. Am I missing something here?
 
 Cheers,
 
 Sarat

Comparisons (<, >, and ==) work for me. Use the ~ for appending and concatenation. I've attached an example that works on my system. If my example doesn't help, it might be useful for you to post a complete example (whether it compiles or not). I'm running WindowsXP. I don't know if my example works on the Linux version (if it doesn't that would probably indicate a compiler bug). Hope this helps. Justin
Oct 07 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Sarat Venugopal" <sarat_ng n0spam.huelix.com> wrote in message
news:blv327$15gn$1 digitaldaemon.com...
 The docs say:

 Strings can be copied, compared, concatenated, and appended:
 char[] str;

 char[] str1 = "abc";

 str1 = str2;

 if (str1 < str3) ...

 func(str3 + str4);

 str4 += str1;

 with the obvious semantics.

 It errors out with "Array operations not implemented". I see that
 concatenantion is supported by ~. Am I missing something here?

The documentation is wrong; '~' is the concatenate operator for strings, not '+'. Similarly, use '~=' for append, not '+='. I've corrected the documentation.
Oct 08 2003