KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Sep-05 13:14 UTC
Gsub jocks - Do you have an example that does this?
I know I''ve been lazy not learning RegExp and gsub but I simply never use it except for this one time. I''ll be importing .csv records and sometimes they''ll be dirty with characters like ( # " ) and I''d like to change these to a space. I would be grateful for a simple example? Thank you, Kathleen --~--~---------~--~----~------------~-------~--~----~ 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 Fri, Sep 5, 2008 at 9:14 AM, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> > I know I''ve been lazy not learning RegExp and gsub but I simply never > use it except for this one time. > I''ll be importing .csv records and sometimes they''ll be dirty with > characters like ( # " ) and I''d like to change these to a space. > I would be grateful for a simple example? > Thank you, > Kathleenline.gsub!(/[#"]/,'' '') the start / and end / define the regex. [#"] means ''match any one of the following: # and " '' the gsub-bang (gsub!) method will change the contents of the line variable. If you''re more cautious do clean_line = line.gsub(...) -- Tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---