Hi, Can anyone help me? I have strings like, 1,2,A and 4, 5, B. When I insert into the table, I want it to be like this: id my_string 1 1 2 A 2 4 5 B instead of id my_string 1 1,2,A 2 4, 5, B How can I achieve that? I have read some where that I could use replace(). But I still don''t know how to use it. Is there a better way? If not how do I use replace() ? 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 -~----------~----~----~----~------~----~------~--~---
user splash wrote:> How can I achieve that? I have read some where that I could use > replace(). But I still don''t know how to use it. Is there a better way? > If not how do I use replace() ? >Hi, I have found gsub() example. It works in the console but it doesn''t work in the controller. Des anyone knows why? 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 -~----------~----~----~----~------~----~------~--~---
On Feb 13, 2008, at 5:41 PM, user splash wrote:> I have strings like, 1,2,A and 4, 5, B. > [and I want] 1,2,A [and] 4, 5, BI use the following NEW_DATA = OLD_DATA.gsub(/\s*,\s*/, '','') or YOUR_DATA.gsub!(/\s*,\s*/, '','') So that it takes care of variations like this: 1, 2,3 , 4 -- def gw writes_at ''www.railsdev.ws'' end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can even do something like:
"1,2,A".split(",").join(" ")
Not sure which one is the fastest though.
On 2/13/08, Greg Willits <lists-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org>
wrote:>
> On Feb 13, 2008, at 5:41 PM, user splash wrote:
>
> > I have strings like, 1,2,A and 4, 5, B.
> > [and I want] 1,2,A [and] 4, 5, B
>
>
> I use the following
>
> NEW_DATA = OLD_DATA.gsub(/\s*,\s*/, '','')
> or
> YOUR_DATA.gsub!(/\s*,\s*/, '','')
>
> So that it takes care of variations like this:
> 1, 2,3 , 4
>
> --
> def gw
> writes_at ''www.railsdev.ws''
> end
>
>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Greg Willits wrote:>I use the following > >NEW_DATA = OLD_DATA.gsub(/\s*,\s*/, '','') >or >YOUR_DATA.gsub!(/\s*,\s*/, '','') > >So that it takes care of variations like this: > 1, 2,3 , 4Love AJAX wrote:> You can even do something like: > "1,2,A".split(",").join(" ") > > Not sure which one is the fastest though.Thanks guys. Problem solved :D -- 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 -~----------~----~----~----~------~----~------~--~---