![]() |
Double quote escape character
Hi all,
I'm trying to export a string to a excel file using fastercsv and I wanted it double quote to make it safer. So i tried to use the escape character \" to insert double quotes but it doesn't work: - string produces string with no quotes in the file - "\"" << string << "\"" produces """string""" - "\"" + string + "\"" produces """string""" I have no idea on how to solve this. Thanks for the help, Alvaro. -- Posted via http://www.ruby-forum.com/. |
Re: Double quote escape character
Hi all,
I think there is not problem at all as it seems that the FasterCSV class is the one who's erasing the double quotes while converting the strings to cvs. Anyway, it's still interesting to notice that there's no possible way to write in Ruby a string like this: ""hello"" Regards, Alvaro. -- Posted via http://www.ruby-forum.com/. |
Re: Double quote escape character
On Aug 16, 2007, at 10:26 AM, Alvaro Perez wrote:
> I'm trying to export a string to a excel file using fastercsv and I > wanted it double quote to make it safer. FasterCSV handles all the quoting for you. That's why you use it. So you should just be doing something like: fcsv << %w[array of fields for row here] James Edward Gray II |
Re: Double quote escape character
Alvaro Perez wrote:
> Hi all, > > I'm trying to export a string to a excel file using fastercsv and I > wanted it double quote to make it safer. So i tried to use the escape > character \" to insert double quotes but it doesn't work: > > - string produces string with no quotes in the file > > - "\"" << string << "\"" produces """string""" > > - "\"" + string + "\"" produces """string""" > > I have no idea on how to solve this. You don't need to quote your output - FasterCSV quotes it iff necessary. Try sticking a '"' in the middle of your string and see what it does. -- Alex |
Re: Double quote escape character
On Aug 16, 11:26 am, Alvaro Perez <alvaro.pmarti...@gmail.com> wrote:
> Hi all, > > I'm trying to export a string to a excel file using fastercsv and I > wanted it double quote to make it safer. So i tried to use the escape > character \" to insert double quotes but it doesn't work: > > - string produces string with no quotes in the file > > - "\"" << string << "\"" produces """string""" > > - "\"" + string + "\"" produces """string""" > > I have no idea on how to solve this. > > Thanks for the help, > Alvaro. > -- > Posted viahttp://www.ruby-forum.com/. try this: irb > str = "foo" > str2 = %Q{#{str}} > p str2 I think that's what you're looking for. |
Re: Double quote escape character
On 8/16/07, Alvaro Perez <alvaro.pmartinez@gmail.com> wrote:
> Hi all, > > I think there is not problem at all as it seems that the FasterCSV class > is the one who's erasing the double quotes while converting the strings > to cvs. > > Anyway, it's still interesting to notice that there's no possible way to > write in Ruby a string like this: > > ""hello"" Sure there is. '"hello"' '""hello""' "\"hello\"" "\"\"hello\"\"" %{"hello"} %{""hello""} <<-EOS "hello" ""hello"" EOS (Okay, that last one actually makes a multi-line string, but the point remains the same.) -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca |
Re: Double quote escape character
On Aug 16, 2007, at 10:37 AM, Alvaro Perez wrote:
> Anyway, it's still interesting to notice that there's no possible > way to > write in Ruby a string like this: > > ""hello"" Sure there is: %Q{"hello"} James Edward Gray II |
Re: Double quote escape character
On 8/16/07, Alvaro Perez <alvaro.pmartinez@gmail.com> wrote:
> Anyway, it's still interesting to notice that there's no possible way to > write in Ruby a string like this: > > ""hello"" > irb(main):001:0> puts "\"\"hello\"\"" ""hello"" => nil ?, -Harold |
Re: Double quote escape character
It´s a bit strange this.
On my irb: irb(main):053:0> p "\"hello\"" "\"hello\"" irb(main):049:0> h = '""hello""' => "\"\"hello\"\"" irb(main):044:0> string = "hello" => "hello" irb(main):046:0> %Q{#{string}} => "hello" irb(main):047:0> p string "hello" irb(main):048:0> puts "\"\"hello\"\"" ""hello"" I´m not pretty sure, but the last one it´s the only that seems to produce exactly what i was looking for... Because "\"\"hello\"\"" != ""hello"" right? or it is altough irb shows it in different ways? -- Posted via http://www.ruby-forum.com/. |
Re: Double quote escape character
On 8/16/07, Alvaro Perez <alvaro.pmartinez@gmail.com> wrote:
> It=B4s a bit strange this. > > On my irb: > > irb(main):053:0> p "\"hello\"" > "\"hello\"" puts "\"hello\"" # =3D> "hello" puts "\"\"hello\"\"" # =3D> ""hello"" p uses #inspect, which usually escapes certain values. IRB uses #inspect, t= oo. -austin --=20 Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca |
| All times are GMT. The time now is 06:05 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.