From: Robin Stocker Date: 2006-08-13T07:14:51+09:00 Subject: Re: ruby equiv of perl pos snacktime wrote: > Or to be more exact, how would I do the following in ruby? > > while ($string =~ /\0/g) { > $new_string .= sprintf '\%o', (pos $string) - 1; > } Another idea: string = "one\0two\0threeeeeee\0" result = '' string.scan(/\0/) do result << '\%o' % $`.length end puts result #=> \3\7\22 Robin