Menu

#2 + operator should concatenate operands

open
nobody
None
5
2006-01-26
2004-03-25
No

The + operator should concatenate the operands if
*either* of them is a string, not only both. That way,
"abc " + 10.0 should return "abc 10.0".

A simple implementation using String.valueOf() for both
operands would be good enough. There's an attached
patch that does exactly that.

Discussion

  • Marcus Brito

    Marcus Brito - 2004-03-25
     
  • Richard Morris

    Richard Morris - 2004-05-18

    Logged In: YES
    user_id=743015

    An alternative is to implement a Str function which would
    turn any object into a String. So it would be possible
    to do 'Str(1) + Str(2)'.

     
  • Nobody/Anonymous

    Logged In: NO

    I agree.

    Please verify that

    "A" + 1 + 2 should be "A12" (not A3B)
    "A" + (1 + 2) should be "A3"
    1 + "A" + 2 should be "1A2"
    1 + 2 + "A" should be "3A"

    just like Java.

     
  • Nathan Funk

    Nathan Funk - 2006-01-26
    • labels: 434210 -->
    • milestone: 219423 -->
     

Log in to post a comment.

MongoDB Logo MongoDB