ruby 1.8.6 puts outputs \000 chars

J

John

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 Mahoney
Homepage: 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"
 
R

Rob Biedenharn

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 Mahoney
Homepage: 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"


Is the file system using UTF-16 perhaps?

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
R

Rick DeNatale

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)
=A0 =A0Author: Patrick Mahoney
=A0 =A0Homepage: http://aalib-ruby.rubyforge.org/

----- lister.rb =A0program

t=3D IO.readlines("gems2.txt")
puts "hello".inspect
puts t[0].inspect =A0 =A0 =A0 =A0#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"

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?
--=20
Rick DeNatale

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

Matt Neuburg

John said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top