On Sun, Apr 25, 2004 at 07:44:05AM +0900, Mike Stok wrote: > Michael Neumann <mneumann / ntecs.de> writes: > > > 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? > > You could use String#split e.g. > > irb(main):001:0> "abc\000def\000".split(/\0/) > => ["abc", "def"] Sure this works. But I want to mix it with other data-types like: "\100String\000\100".unpack("CTC") # T=null-term string # => [64, "String", 64] Otherwise I have to write: str = "\100String\000\100" a, str = str.unpack("Ca*") b, str = str.split("\000", 2) c, _ = str.unpack("Ca*") p [a, b, c] # => [64, "String", 64] Which is a bit ugly :-) Pyhtons struct.unpack has a "s" format specifier which does exactly what I want. Perl and Ruby doesn't have this. http://www.python.org/doc/current/lib/module-struct.html Regards, Michael