473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 14980
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Stephen Ferg | last post by:
I have a question that is not directly Python-related. But I thought I'd ask the most erudite group that I know... :-) When did Windows start accepting the forward slash as a path separator...
2
by: Greg Collins [Microsoft MVP] | last post by:
In reviewing my web site statistics, I see that I get 404 errors (often enough to make me ask about it) when users try to click on a link to a secure external site (i.e. an https:// link). I've...
2
by: Perl Beginner | last post by:
Hi, Is there a way to find a line in a text file that starts with a forward slash? This is how i find a line in text file that starts with a word and then print that line to another text file: ...
4
by: destroooooy | last post by:
Hi folks, I'm finding some (what I consider) curious behavior with the string methods and the forward slash character. I'm writing a program to rename mp3 files based on their id3 tags, and I want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.