[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie Question: Escaping special characters in array of strings

jenjhiz

11/21/2004 11:29:00 PM

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
5 Answers

Florian Gross

11/21/2004 11:38:00 PM

0

Gene Kahn wrote:

> 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"]

Jamis Buck

11/21/2004 11:46:00 PM

0

Gene Kahn wrote:
> 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

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...


Dave Burt

11/22/2004 12:42:00 AM

0

"Gene Kahn" <jenjhiz@yahoo.com> wrote:
> 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"]


jenjhiz

11/22/2004 5:55:00 AM

0

(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 <jgb3@email.byu.edu> wrote in message news:<41A128B9.5000206@email.byu.edu>...
> Gene Kahn wrote:
> > 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

David N. Springer

11/22/2004 3:33:00 PM

0

Gene Kahn wrote:

>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"]

--
David N. Springer Phone: (715) 830-1200 Ext. 126
Silicon Logic Engineering, Inc. FAX: (715) 830-1887
7 South Dewey Street, Suite 1 Mailto:springer@siliconlogic.com
Eau Claire, WI 54701 Web: http://www.silico...