Forum: Ruby on Rails Remove Commas from String

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3efac2b493d393d9a8f00a90d4a051ed?d=identicon&s=25 David Lelong (drlelon)
on 2007-01-02 23:22
Hi,

I have a comma-delimited list of email addresses like:

email1, email2, email3...

that I am adding into individual rows in a database.

How do I remove the commas prior to inserting the data into the
database?

Thanks,

David
19fe735490c8f7e08d5c2de7dc25c826?d=identicon&s=25 Jason Frankovitz (Guest)
on 2007-01-02 23:32
(Received via mailing list)
is this a string separated with commas, or an array?

if it's a string: the_string.gsub(/\,/,"")

...should do it (not tested, sorry).

-Jason
282f2ffbebd0c2c7f4daaac8bb3e212a?d=identicon&s=25 Omar Qazi (Guest)
on 2007-01-02 23:36
(Received via mailing list)
You'll probably want to get the data into an array and add each item
then. Try this:

emails = "omar@roflsoftware.com, aleena@aleenazworld.com,
bleh@bleh.com, feemqa@gmail.com"

email_arr = emails.split(", ")

email_arr.each do | email |
   save_email_to_database(email) #Dummy method, replace with
something real
end
This topic is locked and can not be replied to.