Remove Commas from String


#1

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


#2

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


#3

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, 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
end