From: Paolo Bonzini Date: 2007-11-08T23:55:31+09:00 Subject: Re: Buffer to string On Nov 8, 3:38 pm, Tom M wrote: > On Nov 8, 7:24 am, Jari Williamsson > > wrote: > > I have a buffer (stored in a String class) with a NULL-terminated > > C-style string inside, what's the most efficient approach to get that > > text string up to the NULL? > > > Best regards, > > > Jari Williamsson > > Would buf.unpack("a*") work? No, that's buf.unpack("Z*") that you want irb(main):001:0> s = "hi" => "hi" irb(main):002:0> s << 0.chr => "hi\000" irb(main):003:0> s << "there" => "hi\000there" irb(main):007:0> s.unpack("a*") => ["hi\000there"] irb(main):014:0> s.unpack("Z*") => ["hi"]