[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to escape spaces

Jonathan Wallace

10/1/2006 1:28:00 AM

I'm using ruby 1.8.4. I'm trying to use the gsub function to escape
spaces in a linux path that is stored in a variable.

When I attempt the following, t = "a B"; t.gsub(/ /, "\\ "), I receive
the following output:

irb(main):001:0> t = "a B"; t.gsub(/ /, "\\ ")
=> "a\\ B"

I'd like to get "a\ B" (without quotes, of course). Can someone point
me in the proper direction? Note: I've tried many different variations
with no luck.
Thanks,
Jonathan

13 Answers

Gavin Kistner

10/1/2006 3:08:00 AM

0

Jonathan Wallace wrote:
> I'm using ruby 1.8.4. I'm trying to use the gsub function to escape
> spaces in a linux path that is stored in a variable.

See
http://www.archivum.info/comp.lang.ruby/2005-09/msg...
or
http://wiki.rubygarden.org/Ruby/page/show/Rege...

Reprisal

10/1/2006 3:14:00 AM

0

Your trouble isn't with your gsub patterns I don't believe but with
what you are seeing in irb.

irb(main):107:0> t="a B"
=> "a B"
irb(main):108:0> t.gsub(/ /,"\\")
=> "a\\B"
irb(main):109:0> puts t.gsub(/ /,"\\")
a\B
=> nil
irb(main):110:0> 92.chr
=> "\\"
irb(main):111:0> puts 92.chr
=> nil
irb(main):112:0> Regexp::escape(t)
=> "a\\ B"
irb(main):113:0> puts Regexp::escape(t)
a\ B
=> nil

On Sep 30, 2006, at 9:30 PM, Jonathan Wallace wrote:

> I'm using ruby 1.8.4. I'm trying to use the gsub function to escape
> spaces in a linux path that is stored in a variable.
>
> When I attempt the following, t = "a B"; t.gsub(/ /, "\\ "), I receive
> the following output:
>
> irb(main):001:0> t = "a B"; t.gsub(/ /, "\\ ")
> => "a\\ B"
>
> I'd like to get "a\ B" (without quotes, of course). Can someone point
> me in the proper direction? Note: I've tried many different
> variations
> with no luck.
> Thanks,
> Jonathan
>
>


MonkeeSage

10/1/2006 4:18:00 AM

0

The representation of a backslash (\) is an escaped backslash (\\);
when the later is evaluated by the interpreter (i.e., you ask for its
value) you get the former. You can check the length of the string, or
just print it out, to see this:

s='a\b' # => "a\\b"
s.length # => 3
puts s # => a\b

Regards,
Jordan

M forever

8/20/2011 9:12:00 PM

0

On Aug 20, 4:01 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> Steve de Mena wrote:
> > On 8/11/11 9:31 PM, Bob Harper wrote:
> > > My local classical station (KQAC in Portland) just broadcast what
> > > was announced as the Bruckner 5th Symphony. I was shopping when it
> > > began, so didn't hear the intro, but I knew pretty quickly that
> > > something wasn't kosher. I'd concluded by the end--after a dozen or
> > > so cymbal clashes--that this must be the Schalk version, about
> > > which I'd read but had never heard. Interesting, in a horrible
> > > way--once. Sadly, no mention was made of the 'version' (adaptation
> > > seems a better word) used, though when I heard Leon Botstein
> > > announced as the conductor I knew what it was.
>
> > > I sent a note to the announcer regarding the lack of information
> > > about the version (to be fair, he may have said something in the
> > > intro I didn't hear); it'll be interesting to see whether I get a
> > > response.
>
> > > Bob Harper
>
> > You should have called the station to get the information.  
>
> Why should mailing them not work?
>
>
>
> > We used to
> > set aside 4-5PM weekdays for listeners to call in and ask programming
> > questions.  The announcer could have pre-recorded the show weeks ago
> > and have no recollection of the performance (generally the announcers
> > don't even choose the music), whereas the music librarians/programmers
> > have all that information available.  I hated that hour of taking
> > listener calls when I did it!!
>
> That was a job because the announcers didn't do theirs.

I think Steve has killfiled you, so you probably won't get a reply.
Just wanted to let you know. Although it doesn't matter because hardly
anyone ever replies to you other than to put you in your place, but
you still comment on everything and anything.

Gerard

8/20/2011 9:29:00 PM

0

M forever wrote:
> On Aug 20, 4:01 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > Steve de Mena wrote:
> > > On 8/11/11 9:31 PM, Bob Harper wrote:
> > > > My local classical station (KQAC in Portland) just broadcast
> > > > what was announced as the Bruckner 5th Symphony. I was shopping
> > > > when it began, so didn't hear the intro, but I knew pretty
> > > > quickly that something wasn't kosher. I'd concluded by the
> > > > end--after a dozen or so cymbal clashes--that this must be the
> > > > Schalk version, about which I'd read but had never heard.
> > > > Interesting, in a horrible way--once. Sadly, no mention was
> > > > made of the 'version' (adaptation seems a better word) used,
> > > > though when I heard Leon Botstein announced as the conductor I
> > > > knew what it was.
> >
> > > > I sent a note to the announcer regarding the lack of information
> > > > about the version (to be fair, he may have said something in the
> > > > intro I didn't hear); it'll be interesting to see whether I get
> > > > a response.
> >
> > > > Bob Harper
> >
> > > You should have called the station to get the information.
> >
> > Why should mailing them not work?
> >
> >
> >
> > > We used to
> > > set aside 4-5PM weekdays for listeners to call in and ask
> > > programming questions. The announcer could have pre-recorded the
> > > show weeks ago and have no recollection of the performance
> > > (generally the announcers don't even choose the music), whereas
> > > the music librarians/programmers have all that information
> > > available. I hated that hour of taking listener calls when I did
> > > it!!
> >
> > That was a job because the announcers didn't do theirs.
>
> I think Steve has killfiled you, so you probably won't get a reply.
> Just wanted to let you know. Although it doesn't matter because hardly
> anyone ever replies to you other than to put you in your place, but
> you still comment on everything and anything.

Pointless post.

M forever

8/20/2011 9:39:00 PM

0

On Aug 20, 5:29 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> M forever wrote:
> > On Aug 20, 4:01 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > > Steve de Mena wrote:
> > > > On 8/11/11 9:31 PM, Bob Harper wrote:
> > > > > My local classical station (KQAC in Portland) just broadcast
> > > > > what was announced as the Bruckner 5th Symphony. I was shopping
> > > > > when it began, so didn't hear the intro, but I knew pretty
> > > > > quickly that something wasn't kosher. I'd concluded by the
> > > > > end--after a dozen or so cymbal clashes--that this must be the
> > > > > Schalk version, about which I'd read but had never heard.
> > > > > Interesting, in a horrible way--once. Sadly, no mention was
> > > > > made of the 'version' (adaptation seems a better word) used,
> > > > > though when I heard Leon Botstein announced as the conductor I
> > > > > knew what it was.
>
> > > > > I sent a note to the announcer regarding the lack of information
> > > > > about the version (to be fair, he may have said something in the
> > > > > intro I didn't hear); it'll be interesting to see whether I get
> > > > > a response.
>
> > > > > Bob Harper
>
> > > > You should have called the station to get the information.
>
> > > Why should mailing them not work?
>
> > > > We used to
> > > > set aside 4-5PM weekdays for listeners to call in and ask
> > > > programming questions. The announcer could have pre-recorded the
> > > > show weeks ago and have no recollection of the performance
> > > > (generally the announcers don't even choose the music), whereas
> > > > the music librarians/programmers have all that information
> > > > available. I hated that hour of taking listener calls when I did
> > > > it!!
>
> > > That was a job because the announcers didn't do theirs.
>
> > I think Steve has killfiled you, so you probably won't get a reply.
> > Just wanted to let you know. Although it doesn't matter because hardly
> > anyone ever replies to you other than to put you in your place, but
> > you still comment on everything and anything.
>
> Pointless post.

Like I said: it doesn't matter whether or not Steve can even see or
would want to reply to you, so yes, pointing that out was indeed
pointless. But then replying to any of your posts is pointless, other
than to see the little doggy go for the stick once again.
Like you just did.

Gerard

8/20/2011 9:55:00 PM

0

M forever wrote:
> On Aug 20, 5:29 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > M forever wrote:
> > > On Aug 20, 4:01 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com>
> > > wrote:
> > > > Steve de Mena wrote:
> > > > > On 8/11/11 9:31 PM, Bob Harper wrote:
> > > > > > My local classical station (KQAC in Portland) just broadcast
> > > > > > what was announced as the Bruckner 5th Symphony. I was
> > > > > > shopping when it began, so didn't hear the intro, but I
> > > > > > knew pretty quickly that something wasn't kosher. I'd
> > > > > > concluded by the end--after a dozen or so cymbal
> > > > > > clashes--that this must be the Schalk version, about which
> > > > > > I'd read but had never heard. Interesting, in a horrible
> > > > > > way--once. Sadly, no mention was made of the 'version'
> > > > > > (adaptation seems a better word) used, though when I heard
> > > > > > Leon Botstein announced as the conductor I knew what it was.
> >
> > > > > > I sent a note to the announcer regarding the lack of
> > > > > > information about the version (to be fair, he may have said
> > > > > > something in the intro I didn't hear); it'll be interesting
> > > > > > to see whether I get a response.
> >
> > > > > > Bob Harper
> >
> > > > > You should have called the station to get the information.
> >
> > > > Why should mailing them not work?
> >
> > > > > We used to
> > > > > set aside 4-5PM weekdays for listeners to call in and ask
> > > > > programming questions. The announcer could have pre-recorded
> > > > > the show weeks ago and have no recollection of the performance
> > > > > (generally the announcers don't even choose the music),
> > > > > whereas the music librarians/programmers have all that
> > > > > information available. I hated that hour of taking listener
> > > > > calls when I did it!!
> >
> > > > That was a job because the announcers didn't do theirs.
> >
> > > I think Steve has killfiled you, so you probably won't get a
> > > reply. Just wanted to let you know. Although it doesn't matter
> > > because hardly anyone ever replies to you other than to put you
> > > in your place, but you still comment on everything and anything.
> >
> > Pointless post.
>
> Like I said: it doesn't matter whether or not Steve can even see or
> would want to reply to you, so yes, pointing that out was indeed
> pointless. But then replying to any of your posts is pointless, other
> than to see the little doggy go for the stick once again.
> Like you just did.

Actually, *all* your post are pointless.
You always say things you've said thousands of times before. Forever.



M forever

8/20/2011 10:00:00 PM

0

On Aug 20, 5:55 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> M forever wrote:
> > On Aug 20, 5:29 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > > M forever wrote:
> > > > On Aug 20, 4:01 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com>
> > > > wrote:
> > > > > Steve de Mena wrote:
> > > > > > On 8/11/11 9:31 PM, Bob Harper wrote:
> > > > > > > My local classical station (KQAC in Portland) just broadcast
> > > > > > > what was announced as the Bruckner 5th Symphony. I was
> > > > > > > shopping when it began, so didn't hear the intro, but I
> > > > > > > knew pretty quickly that something wasn't kosher. I'd
> > > > > > > concluded by the end--after a dozen or so cymbal
> > > > > > > clashes--that this must be the Schalk version, about which
> > > > > > > I'd read but had never heard. Interesting, in a horrible
> > > > > > > way--once. Sadly, no mention was made of the 'version'
> > > > > > > (adaptation seems a better word) used, though when I heard
> > > > > > > Leon Botstein announced as the conductor I knew what it was.
>
> > > > > > > I sent a note to the announcer regarding the lack of
> > > > > > > information about the version (to be fair, he may have said
> > > > > > > something in the intro I didn't hear); it'll be interesting
> > > > > > > to see whether I get a response.
>
> > > > > > > Bob Harper
>
> > > > > > You should have called the station to get the information.
>
> > > > > Why should mailing them not work?
>
> > > > > > We used to
> > > > > > set aside 4-5PM weekdays for listeners to call in and ask
> > > > > > programming questions. The announcer could have pre-recorded
> > > > > > the show weeks ago and have no recollection of the performance
> > > > > > (generally the announcers don't even choose the music),
> > > > > > whereas the music librarians/programmers have all that
> > > > > > information available. I hated that hour of taking listener
> > > > > > calls when I did it!!
>
> > > > > That was a job because the announcers didn't do theirs.
>
> > > > I think Steve has killfiled you, so you probably won't get a
> > > > reply. Just wanted to let you know. Although it doesn't matter
> > > > because hardly anyone ever replies to you other than to put you
> > > > in your place, but you still comment on everything and anything.
>
> > > Pointless post.
>
> > Like I said: it doesn't matter whether or not Steve can even see or
> > would want to reply to you, so yes, pointing that out was indeed
> > pointless. But then replying to any of your posts is pointless, other
> > than to see the little doggy go for the stick once again.
> > Like you just did.
>
> Actually, *all* your post are pointless.
> You always say things you've said thousands of times before. Forever.

And what could be more pointless than you commenting on all my
pointless posts?

Gerard

8/20/2011 10:18:00 PM

0

M forever wrote:
> On Aug 20, 5:55 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > M forever wrote:
> > > On Aug 20, 5:29 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com>
> > > wrote:
> > > > M forever wrote:
> > > > > On Aug 20, 4:01 pm, "Gerard"
> > > > > <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > > > > > Steve de Mena wrote:
> > > > > > > On 8/11/11 9:31 PM, Bob Harper wrote:
> > > > > > > > My local classical station (KQAC in Portland) just
> > > > > > > > broadcast what was announced as the Bruckner 5th
> > > > > > > > Symphony. I was shopping when it began, so didn't hear
> > > > > > > > the intro, but I knew pretty quickly that something
> > > > > > > > wasn't kosher. I'd concluded by the end--after a dozen
> > > > > > > > or so cymbal clashes--that this must be the Schalk
> > > > > > > > version, about which I'd read but had never heard.
> > > > > > > > Interesting, in a horrible way--once. Sadly, no mention
> > > > > > > > was made of the 'version' (adaptation seems a better
> > > > > > > > word) used, though when I heard Leon Botstein announced
> > > > > > > > as the conductor I knew what it was.
> >
> > > > > > > > I sent a note to the announcer regarding the lack of
> > > > > > > > information about the version (to be fair, he may have
> > > > > > > > said something in the intro I didn't hear); it'll be
> > > > > > > > interesting to see whether I get a response.
> >
> > > > > > > > Bob Harper
> >
> > > > > > > You should have called the station to get the information.
> >
> > > > > > Why should mailing them not work?
> >
> > > > > > > We used to
> > > > > > > set aside 4-5PM weekdays for listeners to call in and ask
> > > > > > > programming questions. The announcer could have
> > > > > > > pre-recorded the show weeks ago and have no recollection
> > > > > > > of the performance (generally the announcers don't even
> > > > > > > choose the music), whereas the music
> > > > > > > librarians/programmers have all that information
> > > > > > > available. I hated that hour of taking listener calls
> > > > > > > when I did it!!
> >
> > > > > > That was a job because the announcers didn't do theirs.
> >
> > > > > I think Steve has killfiled you, so you probably won't get a
> > > > > reply. Just wanted to let you know. Although it doesn't matter
> > > > > because hardly anyone ever replies to you other than to put
> > > > > you in your place, but you still comment on everything and
> > > > > anything.
> >
> > > > Pointless post.
> >
> > > Like I said: it doesn't matter whether or not Steve can even see
> > > or would want to reply to you, so yes, pointing that out was
> > > indeed pointless. But then replying to any of your posts is
> > > pointless, other than to see the little doggy go for the stick
> > > once again.
> > > Like you just did.
> >
> > Actually, *all* your post are pointless.
> > You always say things you've said thousands of times before.
> > Forever.
>
> And what could be more pointless than you commenting on all my
> pointless posts?

See?
There you say the same thing again. And again. And again. Forever.

M forever

8/20/2011 10:31:00 PM

0

On Aug 20, 6:18 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> M forever wrote:
> > On Aug 20, 5:55 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > > M forever wrote:
> > > > On Aug 20, 5:29 pm, "Gerard" <ghe_no_spam_ndrik...@hotmail.com>
> > > > wrote:
> > > > > M forever wrote:
> > > > > > On Aug 20, 4:01 pm, "Gerard"
> > > > > > <ghe_no_spam_ndrik...@hotmail.com> wrote:
> > > > > > > Steve de Mena wrote:
> > > > > > > > On 8/11/11 9:31 PM, Bob Harper wrote:
> > > > > > > > > My local classical station (KQAC in Portland) just
> > > > > > > > > broadcast what was announced as the Bruckner 5th
> > > > > > > > > Symphony. I was shopping when it began, so didn't hear
> > > > > > > > > the intro, but I knew pretty quickly that something
> > > > > > > > > wasn't kosher. I'd concluded by the end--after a dozen
> > > > > > > > > or so cymbal clashes--that this must be the Schalk
> > > > > > > > > version, about which I'd read but had never heard.
> > > > > > > > > Interesting, in a horrible way--once. Sadly, no mention
> > > > > > > > > was made of the 'version' (adaptation seems a better
> > > > > > > > > word) used, though when I heard Leon Botstein announced
> > > > > > > > > as the conductor I knew what it was.
>
> > > > > > > > > I sent a note to the announcer regarding the lack of
> > > > > > > > > information about the version (to be fair, he may have
> > > > > > > > > said something in the intro I didn't hear); it'll be
> > > > > > > > > interesting to see whether I get a response.
>
> > > > > > > > > Bob Harper
>
> > > > > > > > You should have called the station to get the information.
>
> > > > > > > Why should mailing them not work?
>
> > > > > > > > We used to
> > > > > > > > set aside 4-5PM weekdays for listeners to call in and ask
> > > > > > > > programming questions. The announcer could have
> > > > > > > > pre-recorded the show weeks ago and have no recollection
> > > > > > > > of the performance (generally the announcers don't even
> > > > > > > > choose the music), whereas the music
> > > > > > > > librarians/programmers have all that information
> > > > > > > > available. I hated that hour of taking listener calls
> > > > > > > > when I did it!!
>
> > > > > > > That was a job because the announcers didn't do theirs.
>
> > > > > > I think Steve has killfiled you, so you probably won't get a
> > > > > > reply. Just wanted to let you know. Although it doesn't matter
> > > > > > because hardly anyone ever replies to you other than to put
> > > > > > you in your place, but you still comment on everything and
> > > > > > anything.
>
> > > > > Pointless post.
>
> > > > Like I said: it doesn't matter whether or not Steve can even see
> > > > or would want to reply to you, so yes, pointing that out was
> > > > indeed pointless. But then replying to any of your posts is
> > > > pointless, other than to see the little doggy go for the stick
> > > > once again.
> > > > Like you just did.
>
> > > Actually, *all* your post are pointless.
> > > You always say things you've said thousands of times before.
> > > Forever.
>
> > And what could be more pointless than you commenting on all my
> > pointless posts?
>
> See?
> There you say the same thing again. And again. And again. Forever.

And you will keep posting pointless "replies" to my posts. Forever.