471,852 Members | 939 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

Replacing a backslash with a forward slash in Javascript

In case anyone is interested, this is how I solved the problem of
replacing a back slash with a forward slash (as in being able to access
a document on a file share on an intranet via a browser)

if you cut and paste a path from windows explorer
\\myshare\mydir\mydoc.txt into a form textbox, you can use the
following code to transform it into something usable by a browser:

mytxt = document.myForm.myTextBox.value;
mytxt = mytxt.replace(/\134/g,"/");

\134 is the octal representation of a backslash as a regular
expression. the g is required to replace all instances of the
backslash.

Dec 26 '06 #1
1 14234
Kberg wrote:
mytxt = document.myForm.myTextBox.value;
mytxt = mytxt.replace(/\134/g,"/");

\134 is the octal representation of a backslash as a regular
expression. the g is required to replace all instances of the
backslash.
Why not simply
mytxt = mytxt.replace(/\\/g,"/");
? I am not sure octal escape sequences in regular expression patterns
are standardized and support anywhere.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Greg Collins [Microsoft MVP] | last post: by
4 posts views Thread by destroooooy | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.