Howto replace the " char?

I want to delete the " char from the text:

This is “the Text”.

I want it to be:

This is the Text.

Mark T. wrote:

I want to delete the " char from the text:

This is “the Text”.

I want it to be:

This is the Text.

This is the command where I want to use it:

FasterCSV.foreach(file, :headers =>true, :col_sep =>"\t", :row_sep
=>"\n") do |row|

and the file includes " chars which I want to replace. Can I do
something like:

FasterCSV.foreach(file.gsub!(/^["]/,’’), :headers =>true, :col_sep
=>"\t", :row_sep =>"\n") do |row|

lookup gsub under the String class

On Dec 27, 2007, at 8:18 AM, Mark T. wrote:

I want to delete the " char from the text:

This is “the Text”.

I want it to be:

This is the Text.

http://www.ruby-doc.org/core/classes/String.html

and look at gsub

Peace,
Phillip

You can use the single quote instead for your case.

Phillip K. wrote:

On Dec 27, 2007, at 8:18 AM, Mark T. wrote:

I want to delete the " char from the text:

This is “the Text”.

I want it to be:

This is the Text.

class String - RDoc Documentation

and look at gsub

Peace,
Phillip

I have looked into the gsub commands, but the problem is that it is not
a regular char. I mean it shouldn´t be any problem if it is a % or &
char, but the " char is special character in Ruby for the String.
Any idea?

On Dec 27, 2007 9:47 AM, Mark T. [email protected]
wrote:

===>

This is the Text.

What is the command to simple replace the " char with nothing?

newstring = string.gsub(/"/, ‘’)

or,

newstring = string.tr(‘"’, ‘’)

Both have ! (bang) versions that operate directly on the receiver
rather than returning the transformed result.

(but what does this have to do with Rails?)

Bob S. wrote:

On Dec 27, 2007 9:47 AM, Mark T. [email protected]
wrote:

===>

This is the Text.

What is the command to simple replace the " char with nothing?

newstring = string.gsub(/"/, ‘’)

or,

newstring = string.tr(‘"’, ‘’)

Both have ! (bang) versions that operate directly on the receiver
rather than returning the transformed result.

(but what does this have to do with Rails?)

Thanks for your answer. Unfortunately it didn´t work when I´m using
fasterCSV. This is the code so you can see what I am trying to do:

file = 'c:\filename.txt'
$KCODE = "utf8"
FasterCSV.foreach(file.tr('"', ''), :headers =>true, :col_sep 

=>“\t”, :row_sep =>“\n”) do |row|
@PriceListFileRow = row
next if row.empty?
a_product = Product.new(
:sku => row[0] ,
:name => row[1] ,
:price => row[2] ,
:salestart => row[3] ,
:saleend => row[4] ,
:category => row[5] ,
:manufacturer => row[6] ,
:manufacturersku => row[7] ,
:othersku => row[8] ,
:producturl => row[9] ,
:stockstatus => row[10] ,
:shipping => row[11])
a_product.save

  • The problem is that fasterCSV read the file before it´s been converted
    with the " char.
  • The second problem that I have with Rails is that åäö letters doesn´t
    been imported correctly even when I use the $KCODE = “utf8” code.

Thank you again and waiting for your answer!

Best regards,

Mark

Why have you posted in two threads about an identical issue? This is not
helping the people who are here to help.

Ryan B. wrote:

Why have you posted in two threads about an identical issue? This is not
helping the people who are here to help.

Because the one who actually could help me in this issue still didn´t
find the topic and sent me a correct answer.

Franz S. wrote:

You can use the single quote instead for your case.

I don´t understand…

I have a text that containing " char and want to delete it from the
text.

This is “the Text”.

===>

This is the Text.

What is the command to simple replace the " char with nothing?