From: Eric Hodel Date: 2003-11-11T14:27:27-08:00 Subject: Re: Backslash substitution question --oJAv8lSwuaQsYd0G Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Ron Coutts (rcoutts@envistatech.com) wrote: > I'm having trouble with backslashes and I don't know what is wrong. I > can't seem to write and expression that will evaluate to a string > containing a single backslash character as in "\". It seems that "\\" > in Ruby evaluates to "\\" not to "\" as I would expect. Below are a few > things I've tried. If anyone could send back a quick answer it would be > much appreciated. >=20 > res =3D "c:/foo/bar".gsub(/\//, "\\") # -> c:\\foo\\bar > res =3D "c:/foo/bar".gsub(/\//, '\\') # -> c:\\foo\\bar > #res =3D "c:/foo/bar".gsub(/\//, "\") # -> syntax error - unterminated > string meets end of file > #res =3D "c:/foo/bar".gsub(/\//, '\') # -> syntax error - unterminated > string meets end of file > res =3D "c:/foo/bar".gsub(/\//) { "\\"} # -> c:\\foo\\bar Ruby maps between / and \ in filenames on win32 just fine, why not let it do the work for you? For cmd.exe, it doesn't cane if you give it \ or /, but tab completion doesn't work on /. (I believe I read somewhere that the guts don't care, since back in the DOS days, but my mind could be addled). See also File.join and File.expand_path --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --oJAv8lSwuaQsYd0G Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/sWJPMypVHHlsnwQRAop4AKC9nNPPYa/D6DwkAapjPBAf5rB2NQCdFDv9 48mLS3fn2QLE6lMZMghOr88= =H0Ef -----END PGP SIGNATURE----- --oJAv8lSwuaQsYd0G--