From: gga Date: 2006-08-13T07:05:11+09:00 Subject: Re: ruby equiv of perl pos snacktime ha escrito: > Or to be more exact, how would I do the following in ruby? > > while ($string =~ /\0/g) { > $new_string .= sprintf '\%o', (pos $string) - 1; > } #!/usr/bin/env ruby new_string = '' string = "\0\0\0asda\0\0\0sdasd" pos = 0 while pos = string.index( /\0/, pos ) match = Regexp.last_match pos += match.size new_string << '\%o' % (pos - 1) end puts new_string