From: Pit Capitain Date: 2006-12-06T19:13:20+09:00 Subject: Re: GOLF: hex string to dotted quad Max Muermann schrieb: > On 12/6/06, Martin DeMello wrote: >> irb(main):021:0> hex_ip = "c0a80167" >> => "c0a80167" >> irb(main):022:0> ip = hex_ip.scan(/../).map {|i| i.to_i(16)}.join(".") >> => "192.168.1.103" > > hex_ip.gsub(/../) {|s| "#{s.hex}."}[0..-2] > > The deletion of the trailing '.' is so ugly... but it's a leetle bit > shorter ;) String#hex is a nice idea. hex_ip.scan(/../).map{|s|s.hex}*"." Regards, Pit