Escaping '

Hi,
I need to replace ’ by '. How can I do that?

Thanks

David N. wrote:

Hi,
I need to replace ’ by '. How can I do that?

Thanks

This was harder than I thought…in “vi”(vim actually) I just had to:

1,$ s/’/\’/g

But Ruby didn’t seem to like that…

Anyway, for reasons unknown to me, this works:

puts “‘hello’”.gsub("’","\\’")

Cheers

John

From: John Pritchard-williams [mailto:[email protected]]

David N. wrote:

> I need to replace ’ by '. How can I do that?

This was harder than I thought…in “vi”(vim actually) I just had to:

1,$ s/‘/\’/g

But Ruby didn’t seem to like that…

Anyway, for reasons unknown to me, this works:

how i wish the behaviour would change.
search the archives. this is a faq :slight_smile:

puts “‘hello’”.gsub(“'”,“\\'”)

if like me, you want to lessen the those fences :slight_smile:
try,

“‘hello’”.gsub(“'”) { “\'” }
#=> “\‘hello\’”

or

“‘hello’”.gsub “'”, %q[\']
#=> “\‘hello\’”

for obvious reason, my brain prefers the former

kind regards -botp

//how i wish the behaviour would change.
search the archives. this is a faq :)//

oops sorry (I did it again)…perhaps you could include the link to
where this is explained though… :slight_smile: