newbie :: Convert integer to string in Ruby

Hi all, Please anybody tell me how to Convert integer to string in Ruby and concat it. Suppose I've a string "ABC" , I want to concat it with a number say "ABC12" . Please help me out. Thanks

aveo wrote:

Hi all, Please anybody tell me how to Convert integer to string in Ruby and concat it. Suppose I've a string "ABC" , I want to concat it with a number say "ABC12" . Please help me out. Thanks

>

"ABC" + 12.to_s

Cheers Mohit.

‘ABC’ + 12.to_s

Other people explained how to concat, let me add that in Ruby you normally interpolate:

   "ABC#{n}"

-- fxn

Generally, the method "to_s" (i.e. 'to string') will convert something into a string representation.

So 12.to_s will return the string "12".

Then you can use one of the string concatenation operators. For example,

  string + integer.to_s

will return your concatenated string. And,

  string << integer.to_s

will modify string in-place by adding integer.to_s to the end of it.

Chris