[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

inline double quotes

John Dax

9/2/2008 7:10:00 AM

hi,
i'm searching for a way to remove inline double quotes in ruby,
especially in a csv file.

sth like "blabla "title" blbl";"bla bla" should become
"blabla 'title' blbl";"bla bla"

thanks in advance
johnny
--
Posted via http://www.ruby-....

1 Answer

TPReal

9/2/2008 8:18:00 AM

0

John Dax wrote:
> hi,
> i'm searching for a way to remove inline double quotes in ruby,
> especially in a csv file.
>
> sth like "blabla "title" blbl";"bla bla" should become
> "blabla 'title' blbl";"bla bla"
>
> thanks in advance
> johnny

Your csv is malformed if it has such quotes, so there is no standard way
to remove them. You'll have to use some regular expression, for example
if all the columns in your file are quoted, and t is a line from your
file, try this:

t.split(/^"|";"|"$/)[1..-1].map{|e| "\"#{e.gsub(/"/,"'")}\""}.join(";")

Probably not the easiest method, but certainly a one-liner.

TPR.
--
Posted via http://www.ruby-....