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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-10 10:10 UTC
Re: newbie :: Convert integer to string in Ruby
''ABC'' + 12.to_s On 10/04/07, aveo <rahul.h-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mohit Sindhwani wrote:> aveo wrote: >> >> >> > "ABC" + 12.to_s > > Cheers > Mohit.great, that was so simple, thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, 11:06 am, "aveo" <rahu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---