From: nobu.nokada@... Date: 2004-04-27T23:40:12+09:00 Subject: Re: String#unpack and null-terminated strings Hi, At Tue, 27 Apr 2004 06:54:03 +0900, daz wrote in [ruby-talk:98456]: > > > s = "abc\0def\0\0jkl\0" > > > > > > s.unpack('Z6Z*Z*') #-> ["abc", "f", ""] > > > > It can't round trip with Array#pack, so I discarded this plan. > > But the user has specified that the first field is > fixed-width(6) and null-terminated so: > > "abc\000de" == "abc\000\000\000" ==> "abc" > > Everything from "\000" to the end of the field is junk > because the user told us so by using 'Z'. > > We don't need to apologise that pack didn't replace the > exact junk that was there before :-? Hmmm, sounds reasonable. -- Nobu Nakada