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:
“ABC” + 12.to_s
Cheers
Mohit.
‘ABC’ + 12.to_s
Mohit S. wrote:
aveo wrote:
“ABC” + 12.to_s
Cheers
Mohit.
great, that was so simple, thanks
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
On Apr 10, 2007, at 12:06 PM, aveo wrote:
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” .
Other people explained how to concat, let me add that in Ruby you
normally interpolate:
“ABC#{n}”
– fxn