"Richard Lionheart" <NoOne / Nowhere.com> schrieb im Newsbeitrag news:ycmdnde8YJUTv3Pd4p2dnA / comcast.com... > Hi All, > > The following Ruby script displays use of a pattern to remove a superfluous > backslash in a string if present. It works as intended with two "toy" > situations, but fails when applied to an environment string running under > Windows. > > Can anyone tell me where I erred? You rather want str.gsub!(/\\$/, '') than str.chop! if you want to remove trailing backslashes. See the documentation for chop!: http://www.ruby-doc.org/docs/rdoc/1.9/classes/String.html#M001300 robert > > TIA, > Richard > > ============ Ruby pgm =========== > > # Executed under Windows 2000 > > s1 = "ab\\\\" > puts "s1 before: \"#{s1}\" (two backslashes)" > s1.chop! if s1.reverse =~ /^\\\\/ > puts "s1 after: \"#{s1}\" (redced to a single backslash)" > > s2 = "ab\\" > puts "s2 before: \"#{s2}\" (single backslash)" > s2.chop! if s2.reverse =~ /^\\\\/ > puts "s2 after: \"#{s2}\" (single backslash, undisturbed)" > > s3 = ENV["UserProfile"] > puts "s3: \"#{s3}\"" > sCookiesPath = s3 + "\\" > puts "Cookies path before: \"#{sCookiesPath}\" (single backslash)" > sCookiesPath.chop! if sCookiesPath.reverse !~ /^\\\\/ > puts "Cookies path after: \"#{sCookiesPath}\" (single backslash removed - > why)" > > <<'OUTPUT' > >rubyw PatternsTest.rb > s1 before: "ab\\" (two backslashes) > s1 after: "ab\" (redced to a single backslash) > s2 before: "ab\" (single backslash) > s2 after: "ab\" (single backslash, undisturbed) > s3: "G:\Documents and Settings\RLMuller" > Cookies path before: "G:\Documents and Settings\RLMuller\" (single > backslash) > Cookies path after: "G:\Documents and Settings\RLMuller" (single backslash > removed - why) > >Exit code: 0 > OUTPUT > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.713 / Virus Database: 469 - Release Date: 7/7/2004 > >