From: Logan Capaldo Date: 2006-07-29T08:50:57+09:00 Subject: Re: Finding "\" in a string On Jul 28, 2006, at 7:25 PM, Paul Battley wrote: > 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. > I'm sure it is. I'll learn how to decipher backslashes in gsub when I come across those strings