Topic: String concatenation ruby way?

is there a Ruby( succint) way of string concatenation in Ruby?
a)
$str = @str1+"ABCD"+@str2+"CFDE"

b)
is this possible? if yes, preferred?
$str.join(str1).join('ABCD')

Re: String concatenation ruby way?

Global variables are bad! wink (just kidding...sort of)

There most assuredly is a good way to concatenate strings.

$str = "#{@str1}ABCD#{@str2}CFDE"

The #{} syntax lets you put variables into strings.

I'm not sure what you're asking with the second question though.

Re: String concatenation ruby way?

RubySmith wrote:

b)
is this possible? if yes, preferred?
$str.join(str1).join('ABCD')

Just use templating like in Firanide's example, it's far more readable.

vinnie - rails forum admin

Re: String concatenation ruby way?

how do i insert a carriage return/linefeed in a concatenated string (say for example a formatted address), as in:?

$str = "#{@addr1}CR/LF#{@addr2}CR/LF#{@addr3}CR/LF#{@state}#{@zip}CR/LF"

Re: String concatenation ruby way?

$str = "#{@addr1}\r\n#{@addr2}\r\n et cetera"

Re: String concatenation ruby way?

thanks a mill matey :-)