Below is the code:
ruby-1.9.2-p290 :019 > "a, , b, c".delete(" , ")
=> "abc"
I want it to be
a, b, c
What have I done wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
deleteremoves all characters occuring in the string you hand over to it (see ruby-doc). What you need is something likeUPDATE:
As mentioned in a comment below, the string is the result of a
join(', '). In this case the better approach would be to remove the empty/nilelements before joining, i.e.