On 2007-11-08, Jari Williamsson <jari.williamsson / mailbox.swipnet.se> wrote: > Paul Irofti wrote: > >> $ irb >> irb(main):001:0> s = "hello\0" >> => "hello\000" >> irb(main):002:0> s.chomp("\0") >> => "hello" > > This particular approach wouldn't work, since it can't be guaranteed > that every byte remaining in the buffer (after the termination) is NULL: > irb(main):001:0> s = "Hello\0\1\0" >=> "Hello\000\001\000" > irb(main):002:0> s.chomp("\0") >=> "Hello\000\001" > > But the other suggestions work. Thanks! > I did not consider trailing garbage, sorry about that. I thought, from your original question, that you only have a NULL terminated string and not anything else. -- everything is simple, we're stupid contact at gmail