Hi,

At Fri, 11 Apr 2003 21:51:58 +0900,
<guillaume.pierronnet / ratp.fr> wrote:
> i wondered that 'Z' or 'A' parameters in String#unpack to return a
> string with characters that follow the first null character removed .

'Z' removes trailing NUL characters.

$ ruby -e 'p "this is my test\000please remove this\0\0\0".unpack("Z*")'
["this is my test\000please remove this"]

> i think this is useful for extracting C null-terminated string that has
> not been filled with null characters.

  string.sub(/\0.*/m, '')

or

  string[/\A[^\0]*/]

-- 
Nobu Nakada