From: daz Date: 2004-04-25T14:34:03+09:00 Subject: Re: String#unpack and null-terminated strings Michael Neumann wrote: > Hi, > > How can I unpack two or more consecutive C-strings with the > String#unpack method? Like this: > > "abc\000def\000".unpack("??") # => ["abc", "def"] > > Currently, this seems not to be possible. Any chance to get the > following patch applied, which implements exactly this? > > [snip] diff -r1.69 pack.c At the risk of being told to clear off and write my own spec., I think that an ambuiguity has intruded into the designers mind. The A and Z string field formats should IMO be recovered from left to right. Doesn't the term "string" relate here to a string element within a packed field. The packed field just happens to be a Ruby String. If this is going to break code, I wish that it could happen from 1.9. As it is now, A and Z are behaving the way I would expect A* and Z* to (i.e. * uses all remaining elements). There's String#rstrip for removing spaces and nulls from the end of a String. Unpack is very useful for decoding structures but with the current behaviour if a structure were to contain a null- terminated string element it would break the flow ... .... as Michael has highlighted. Please, Matz. daz