Stripping double quotes

Hi,

I have the attached file, but my issue is that the file I am parsing, is
in this format:

"45hc43j","sdfsdf","","Dead","sdfdsf ","sgfsdf","","sdfg","null","",

That is why I escape quotes in the script. How do I get an output that
doesn't have double quotes? I tried using gsub but it was of no use.

Also, the data snippet above is a csv file...but if you were to output
it to command line and text after running the script, it returns those
elements as quotes as seen above.

Any help will be appreciated.

Mick

Attachments:
http://www.ruby-forum.com/attachment/6893/parseLICDB.rb

···

--
Posted via http://www.ruby-forum.com/.

Hi,

I have the attached file, but my issue is that the file I am parsing, is
in this format:

"45hc43j","sdfsdf","","Dead","sdfdsf ","sgfsdf","","sdfg","null","",

That is why I escape quotes in the script. How do I get an output that
doesn't have double quotes? I tried using gsub but it was of no use.

How is gsub no use?

    $ irb
    >> string = '"45hc43j","sdfsdf","","Dead","sdfdsf ","sgfsdf","","sdfg","null","",'
    => "\"45hc43j\",\"sdfsdf\",\"\",\"Dead\",\"sdfdsf \",\"sgfsdf\",\"\",\"sdfg\",\"null\",\"\","
    >> new_string = string.gsub('"', '')
    => "45hc43j,sdfsdf,Dead,sdfdsf ,sgfsdf,sdfg,null,"

That seems to work just fine for me.

···

On Tue, Jan 10, 2012 at 07:31:11AM +0900, Mickey Vogel wrote:

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

Hi,

I have the attached file, but my issue is that the file I am parsing, is
in this format:

"45hc43j","sdfsdf","","Dead","sdfdsf ","sgfsdf","","sdfg","null","",

That is why I escape quotes in the script. How do I get an output that
doesn't have double quotes? I tried using gsub but it was of no use.

Also, the data snippet above is a csv file...but if you were to output
it to command line and text after running the script, it returns those
elements as quotes as seen above.

Any help will be appreciated.

Since you are really trying to open a CSV file ... use
the existing CSV library

There are other cases that you might miss (e.g. newlines
inside a "cell" are allowed (e.g. a return inside a cell in
Excell/OpenOffice is possible) and may trip you). Probably
there are more corner cases that are non-trivial in the
beginning.

HTH,

Peter

···

On Mon, Jan 9, 2012 at 11:31 PM, Mickey Vogel <cjose@mail.usp.edu> wrote:

Mick

Attachments:
http://www.ruby-forum.com/attachment/6893/parseLICDB.rb

--
Posted via http://www.ruby-forum.com/\.

--
Peter Vandenabeele
http://twitter.com/peter_v
http://rails.vandenabeele.com
gsm: +32-478-27.40.69
e-mail: peter@vandenabeele.com

Chad Perrin wrote in post #1040132:

How do I get an output that doesn't have double quotes? I tried
using gsub but it was of no use.

How is gsub no use?

Because String#tr() is a better choice. :wink:

new_string = string.gsub('"', '')

new_string = string.tr('"', '')

···

On Tue, Jan 10, 2012 at 07:31:11AM +0900, Mickey Vogel wrote:

--
Posted via http://www.ruby-forum.com/\.