Newbie Question: Escaping special characters in array of strings

G

Gene Kahn

Hello,

Because of the embedded single quote, this statement does not work.

%w[it's you're they're]

Escaping it with the backslash does not work either:

%w[it\'s you\'re they\'re]

How do I escape the single quote and other special characters in this instance?

Thanks!
gk
 
F

Florian Gross

Gene said:
Because of the embedded single quote, this statement does not work.

%w[it's you're they're]

I don't understand. It seems to work fine for me:

irb(main):001:0> %w[it's you're they're]
=> ["it's", "you're", "they're"]
 
J

Jamis Buck

Gene said:
Hello,

Because of the embedded single quote, this statement does not work.

%w[it's you're they're]

Escaping it with the backslash does not work either:

%w[it\'s you\'re they\'re]

How do I escape the single quote and other special characters in this instance?

Thanks!
gk

.

Maybe I don't understand what you mean by "does not work":

irb(main):002:0> %w[it's you they're]
=> ["it's", "you", "they're"]

It seems to work for me...

- Jamis
 
D

Dave Burt

Gene Kahn said:
Hello,

Because of the embedded single quote, this statement does not work.

%w[it's you're they're]

Escaping it with the backslash does not work either:

%w[it\'s you\'re they\'re]

What version of Ruby are you using?

ruby 1.8.1 (2003-12-25) [i386-mswin32]

irb(main):001:0> %w[it's you're they're]
=> ["it's", "you're", "they're"]
irb(main):002:0> %w[it\'s you\'re they\'re]
=> ["it\\'s", "you\\'re", "they\\'re"]
 
G

Gene Kahn

(blushing) I don't understand ... I was using SciTe, and I couldn't
get it to work. But now it works.

Sorry for the wasted time on your part. And thanks!

Cheers!
gk

Jamis Buck said:
Gene said:
Hello,

Because of the embedded single quote, this statement does not work.

%w[it's you're they're]

Escaping it with the backslash does not work either:

%w[it\'s you\'re they\'re]

How do I escape the single quote and other special characters in this instance?

Thanks!
gk

.

Maybe I don't understand what you mean by "does not work":

irb(main):002:0> %w[it's you they're]
=> ["it's", "you", "they're"]

It seems to work for me...

- Jamis
 
D

David N. Springer

Gene said:
Hello,

Because of the embedded single quote, this statement does not work.

%w[it's you're they're]

Escaping it with the backslash does not work either:

%w[it\'s you\'re they\'re]

How do I escape the single quote and other special characters in this instance?

Thanks!
gk
Maybe what you need to do is escape the spaces.

irb(main):001:0> %w[it's\ you're\ they're]
=> ["it's you're they're"]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top