From: Paul Battley Date: 2006-07-29T08:25:57+09:00 Subject: Re: Finding "\" in a string On 29/07/06, Logan Capaldo wrote: > This is why when I need to gsub backslashes I use a block: > > gsub(%r{\}) { '\\' } That's much easier, but significantly slower: s = "\\foo" * 1000000 t0 = Time.now s.gsub("\\", "\\\\\\") p(Time.now - t0) # 1.394492 t0 = Time.now s.gsub("\\"){ "\\\\" } p(Time.now - t0) # 2.863728 If you are dealing with very long strings, it's probably worth the effort of ciphering the backslashes. Paul.