# Ruby 1.8.6 puts outputs \\000 chars

**URL:** <https://www.ruby-forum.com/t/ruby-1-8-6-puts-outputs-000-chars/172970>\
**Category:** Ruby\
**Created:** [July 30, 2009, 5:35pm UTC](https://www.ruby-forum.com/t/ruby-1-8-6-puts-outputs-000-chars/172970 "2009-07-30T17:35:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [July 30, 2009, 5:35pm UTC](https://www.ruby-forum.com/t/ruby-1-8-6-puts-outputs-000-chars/172970/1 "2009-07-30T17:35:40Z")

</div>

I recently updated my gem library, now a simple program outputs \000  
chars.  
What has changed and is causing the \000 after each char output ?  
And how to correct the problem.

Thanks for the help.

----- Snippet of input file:  
aalib-ruby (0.7.1)  
Author: Patrick M.  
Homepage: [http://aalib-ruby.rubyforge.org/](http://aalib-ruby.rubyforge.org/)

----- lister.rb program

t= IO.readlines(“gems2.txt”)  
puts “hello”.inspect  
puts t[0].inspect #print 1st line of file

— output from lister.rb

C:\Users\spanton\Documents\GemList\>ruby lister.rb  
“hello”  
“a\000a\000l\000i\000b\000-\000r\000u\000b\000y\000 \000  
(\0000\000.\0007\000.\00  
01\000)\000\r\000\n”

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [July 30, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/ruby-1-8-6-puts-outputs-000-chars/172970/2 "2009-07-30T18:20:09Z")

</div>

On Jul 30, 2009, at 11:35 AM, John wrote:

> Homepage: [http://aalib-ruby.rubyforge.org/](http://aalib-ruby.rubyforge.org/)  
> “hello”  
> “a\000a\000l\000i\000b\000-\000r\000u\000b\000y\000 \000  
> (\0000\000.\0007\000.\00  
> 01\000)\000\r\000\n”

Is the file system using UTF-16 perhaps?

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [July 30, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/ruby-1-8-6-puts-outputs-000-chars/172970/3 "2009-07-30T18:21:54Z")

</div>

On Thu, Jul 30, 2009 at 11:35 AM, John[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Homepage: [http://aalib-ruby.rubyforge.org/](http://aalib-ruby.rubyforge.org/)  
> “hello”  
> “a\000a\000l\000i\000b\000-\000r\000u\000b\000y\000 \000  
> (\0000\000.\0007\000.\00  
> 01\000)\000\r\000\n”

Hmmmm, my first guess is that the null characters really ARE in the  
file “gems2.txt”

## perhaps it changed since the last time you ran the program?

Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [July 30, 2009, 6:36pm UTC](https://www.ruby-forum.com/t/ruby-1-8-6-puts-outputs-000-chars/172970/4 "2009-07-30T18:36:33Z")

</div>

John [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I recently updated my gem library, now a simple program outputs \000  
> chars.  
> What has changed and is causing the \000 after each char output ?

As others have said, it looks like your input is UTF-16. Either _treat_  
it as UTF-16 or convert it to something else… You _think_ you know  
what the input file looks like when you view it in some other program,  
but that other program is hiding the null bytes from you. They are  
really there. m.
