# Weird conversion in IRB

**URL:** <https://www.ruby-forum.com/t/weird-conversion-in-irb/153779>\
**Category:** Ruby\
**Created:** [November 20, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/weird-conversion-in-irb/153779 "2008-11-20T23:59:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [November 20, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/weird-conversion-in-irb/153779/1 "2008-11-20T23:59:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [November 21, 2008, 12:08am UTC](https://www.ruby-forum.com/t/weird-conversion-in-irb/153779/2 "2008-11-21T00:08:40Z")

</div>

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

??

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [November 21, 2008, 1:43am UTC](https://www.ruby-forum.com/t/weird-conversion-in-irb/153779/3 "2008-11-21T01:43:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [November 21, 2008, 2:19am UTC](https://www.ruby-forum.com/t/weird-conversion-in-irb/153779/4 "2008-11-21T02:19:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [November 21, 2008, 9:55am UTC](https://www.ruby-forum.com/t/weird-conversion-in-irb/153779/5 "2008-11-21T09:55:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nuby2ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/54ee81/32.png) [@nuby2ruby](https://www.ruby-forum.com/u/nuby2ruby)\
**Post date:** [November 21, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/weird-conversion-in-irb/153779/6 "2008-11-21T18:10:29Z")

</div>

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