Forum: Ruby on Rails Remove Commas from String

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
David L. (Guest)
on 2007-01-03 00:22

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


Jason F. (Guest)
on 2007-01-03 00: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).

Omar Q. (Guest)
on 2007-01-03 00:36
(Received via mailing list)
You'll probably want to get the data into an array and add each item
then. Try this:

emails = "removed_email_address@domain.invalid, 
removed_email_address@domain.invalid, removed_email_address@domain.invalid"

email_arr = emails.split(", ")

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