Forum: Ruby Weird conversion in IRB

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jeremy W. (Guest)
on 2008-11-21 00:59
For some reason I have this line I am pasting from a text file into IRB,
and it is converting the spaces into the word "bee"

IF test @yst-hide-felicite

irb(main):001:0> WHENbeeNONEMPTYbee@horizontal-featured-item-text

If I paste it into the normal prompt it works though..

C:\rails_apps\transfer-util>WHEN NONEMPTY @horizontal-featured-item-text

It works everywhere but IRB. The file I am copying this from I made, so
I know they are just spaces.

Anyone else seen anything like this?

~Jeremy
Jeremy W. (Guest)
on 2008-11-21 01:08
Jeremy W. wrote:
> For some reason I have this line I am pasting from a text file into IRB,
> and it is converting the spaces into the word "bee"
>
> IF test @yst-hide-felicite
>
> irb(main):001:0> WHENbeeNONEMPTYbee@horizontal-featured-item-text
>
> If I paste it into the normal prompt it works though..
>
> C:\rails_apps\transfer-util>WHEN NONEMPTY @horizontal-featured-item-text
>
> It works everywhere but IRB. The file I am copying this from I made, so
> I know they are just spaces.
>
> Anyone else seen anything like this?
>
> ~Jeremy

ok, let me re-phrase something. When I made the file, I didn't write it
by hand. I used another script to generate it. I guess in a text editor,
they look like spaces, but when I do a

puts file.readlines[0]

I get back
=> "WHEN\302\240NONEMPTY\302\240@horizontal-featured-item-text2\n"

what is \302\240

??
Jeremy W. (Guest)
on 2008-11-21 02:43
ok, I've been reading more on it. I guess it's like unicode or
something....


anyway, I need help with it still. I have a string,

"FOR-EACH-OBJECT\302\240@contents2\n"

and I want to split it by the \302\240, just doing

string.split('\302\240') doesn't work.

Any ideas?

Thanks,
~Jeremy
Siep K. (Guest)
on 2008-11-21 03:19
Jeremy W. wrote:
> ok, I've been reading more on it. I guess it's like unicode or
> something....
>
>
> anyway, I need help with it still. I have a string,
>
> "FOR-EACH-OBJECT\302\240@contents2\n"
>
> and I want to split it by the \302\240, just doing
>
> string.split('\302\240') doesn't work.
>
> Any ideas?
>
> Thanks,
> ~Jeremy

Splitting with a regex works.

string.split(/\302\240/)

hth,

Siep
Brian C. (Guest)
on 2008-11-21 10:55
Jeremy W. wrote:
> ok, I've been reading more on it. I guess it's like unicode or
> something....

Yep, you can even see the string broken into unicode chars:

irb(main):009:0> src.scan(/./u)
=> ["W", "H", "E", "N", "\302\240", "N", "O", "N", "E", "M", "P", "T",
"Y", "\302\240", "@", "h", "o", "r", "i", "z", "o", "n", "t", "a", "l",
"-", "f", "e", "a", "t", "u", "r", "e", "d", "-", "i", "t", "e", "m",
"-", "t", "e", "x", "t", "2"]

> and I want to split it by the \302\240, just doing
>
> string.split('\302\240') doesn't work.

You need double-quotes, not single-quotes, for the \nnn syntax to be
turned into single bytes.

irb(main):011:0> src.split("\302\240")
=> ["WHEN", "NONEMPTY", "@horizontal-featured-item-text2\n"]
Jeremy W. (Guest)
on 2008-11-21 19:10
wow, that's so weird, but it worked! Thanks man.

~Jeremy

Brian C. wrote:
> Jeremy W. wrote:
>> ok, I've been reading more on it. I guess it's like unicode or
>> something....
>
> Yep, you can even see the string broken into unicode chars:
>
> irb(main):009:0> src.scan(/./u)
> => ["W", "H", "E", "N", "\302\240", "N", "O", "N", "E", "M", "P", "T",
> "Y", "\302\240", "@", "h", "o", "r", "i", "z", "o", "n", "t", "a", "l",
> "-", "f", "e", "a", "t", "u", "r", "e", "d", "-", "i", "t", "e", "m",
> "-", "t", "e", "x", "t", "2"]
>
>> and I want to split it by the \302\240, just doing
>>
>> string.split('\302\240') doesn't work.
>
> You need double-quotes, not single-quotes, for the \nnn syntax to be
> turned into single bytes.
>
> irb(main):011:0> src.split("\302\240")
> => ["WHEN", "NONEMPTY", "@horizontal-featured-item-text2\n"]
This topic is locked and can not be replied to.