From: elof@... Date: 2007-11-08T22:33:18+09:00 Subject: Re: Buffer to string If you really only ever care about the first string then s.match(/\000/).pre_match is an alternative which looks like it could be less work for the machine since it can stop after the first \000 rather than have to split the entire string. Are you looking at strings huge enough that efficiency at this level matters? Kristian On Thu, 8 Nov 2007 22:13:57 +0900, wrote: > > Hi > > One approach could be to use split and a regexp: > > s = "hi" > s << 0.chr > s << "there" > p s > p s.split(/\000/).first > > Kristian > > On Thu, 8 Nov 2007 21:24:34 +0900, Jari Williamsson > wrote: >> I have a buffer (stored in a String class) with a NULL-terminated >> C-style string inside, what's the most efficient approach to get that >> text string up to the NULL? >> >> >> Best regards, >> >> Jari Williamsson