str = “0x22334455”
I need the output as 0x22 0x33 0x44 0x55
How do I use gsub for this example?
str = “0x22334455”
I need the output as 0x22 0x33 0x44 0x55
How do I use gsub for this example?
I’m not sure that you’re phrasing your output as what you really want,
but here’s how to get exactly that:
str[2…-1].gsub(/(\d{2})/,’ 0x\1’).strip
=> “0x22 0x33 0x44 0x55”
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs