473,383 Members | 1,855 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,383 software developers and data experts.

Escaping escape characters in JScript

Hi,

I have been getting hopelessly confused with escaping escape characters in
JScript! All I want to do is write a simple funtion:

function DoubleUpBackSlash(inputString)
{
???????
}

which will do the following:

<%
var inputString = "D:\Internet\test2.txt"
Response.Write(DoubleUpBackSlash(inputString));
%>

....printing out the following on the screen:
D:\\Internet\\test2.txt

Can anyone fill in the blanks in the function for me?

TIA,

JON

Jul 19 '05 #1
14 3511
By the time you're passing the value to your function, you have to already
have the \s escaped. So, if you're hard-coding in the string value, which
you're currently doing, hard-code it with the \s doubled up already.

What are you trying to do with the value afterwards? Are you putting it in
a client-side javascript function? If so, escaping will have to be handled
again, but tell us what you're doing first before we worry about that.

Ray at work

"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
Hi,

I have been getting hopelessly confused with escaping escape characters in
JScript! All I want to do is write a simple funtion:

function DoubleUpBackSlash(inputString)
{
???????
}

which will do the following:

<%
var inputString = "D:\Internet\test2.txt"
Response.Write(DoubleUpBackSlash(inputString));
%>

...printing out the following on the screen:
D:\\Internet\\test2.txt

Can anyone fill in the blanks in the function for me?

TIA,

JON

Jul 19 '05 #2
Hi Ray,

This is what I'm after (see my comments in the code):

<%
var fso = Server.CreateObject("Scripting.FileSystemObject");

//doesn't work
var wfile = fso.CreateTextFile("D:\Internet\test2.txt", true);

//works
var wfile = fso.CreateTextFile(" D:\\Internet\\test2.txt", true);

//want this to work!
var wfile =
fso.CreateTextFile(DoubleUpBackSlash("D:\Internet\ test2.txt"), true);

wfile.WriteLine("This is a test.");
wfile.Close();
fso = null;
%>

Thanks,

JON

Jul 19 '05 #3
The //want this to work won't work in jscript! Is there any particular
reason that you don't want want to use the built-in escape functionality
that is required? You can't just elect to not use it. If you share the
reason for your desire, you may be surprised by a creative solution!

Ray at work

"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
Hi Ray,

This is what I'm after (see my comments in the code):

<%
var fso = Server.CreateObject("Scripting.FileSystemObject");

//doesn't work
var wfile = fso.CreateTextFile("D:\Internet\test2.txt", true);

//works
var wfile = fso.CreateTextFile(" D:\\Internet\\test2.txt", true);

//want this to work!
var wfile =
fso.CreateTextFile(DoubleUpBackSlash("D:\Internet\ test2.txt"), true);

wfile.WriteLine("This is a test.");
wfile.Close();
fso = null;
%>

Thanks,

JON


Jul 19 '05 #4
"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
Hi Ray,

This is what I'm after (see my comments in the code):

<%
var fso = Server.CreateObject("Scripting.FileSystemObject");

//doesn't work
var wfile = fso.CreateTextFile("D:\Internet\test2.txt", true);

//works
var wfile = fso.CreateTextFile(" D:\\Internet\\test2.txt", true);

//want this to work!
var wfile =
fso.CreateTextFile(DoubleUpBackSlash("D:\Internet\ test2.txt"), true);

wfile.WriteLine("This is a test.");
wfile.Close();
fso = null;
%>

Thanks,

JON


Unfortunately, it can't be done. It's the equivalent of trying to create the
DoubleUpQuote function in VBScript. By the time you construct the string to
pass to the function it's already too late. Sort of a weird catch-22
situation.
Jul 19 '05 #5
Jon Maz wrote:
Hi Ray,

This is what I'm after (see my comments in the code):

<%
var fso = Server.CreateObject("Scripting.FileSystemObject");

//doesn't work
var wfile = fso.CreateTextFile("D:\Internet\test2.txt", true);

//works
var wfile = fso.CreateTextFile(" D:\\Internet\\test2.txt", true);

//want this to work!
var wfile =
fso.CreateTextFile(DoubleUpBackSlash("D:\Internet\ test2.txt"),
true);

wfile.WriteLine("This is a test.");
wfile.Close();
fso = null;
%>

Thanks,

JON


If you are supplying a string literal (as above) you would have had to
already have typed in the \\ in order to get the string properly
interpreted. It's the same as if you typed in a string literal containing a
quote in vbscript:

s = "he said "something""

This would not be correctly interpreted either until you doubled the quotes.
s = "he said ""something"""

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #6
Hi Ray,

Reason's simple - it was a pain in the you-know-where copying file paths out
of a browser address window and manually doubling up the back slashes, so I
just thought I'd try to automate the process instead...

Cheers,

J
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004
Jul 19 '05 #7
Hi Bob & Chris,

Thanks, that explains what was screwy in my logic!

Cheers,

JON
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004
Jul 19 '05 #8
Wouldn't the browser address use a /?

If your values are already in variables, you don't have to escape the \. If
you have a variable with a value of "D:\Path" you don't have to escape that.

Again, if you show us what you're doing, you may find an answer.

Ray at work
"Jon Maz" <jo****@surfeu.de.NOSPAM> wrote in message
news:e5****************@TK2MSFTNGP15.phx.gbl...
Hi Ray,

Reason's simple - it was a pain in the you-know-where copying file paths
out
of a browser address window and manually doubling up the back slashes, so
I
just thought I'd try to automate the process instead...

Cheers,

J
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004

Jul 19 '05 #9
Sorry Ray, I meant the Windows Explorer address bar, not browser address
bar.

J


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004
Jul 19 '05 #10
How are you pulling in a Windows Explorer address bar from ASP code?

Ray at work

"Jon Maz" <jo****@surfeuNOSPAM.de> wrote in message
news:u%***************@TK2MSFTNGP15.phx.gbl...
Sorry Ray, I meant the Windows Explorer address bar, not browser address
bar.

J


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004

Jul 19 '05 #11
Jon Maz wrote:
//want this to work!
var wfile =
fso.CreateTextFile(DoubleUpBackSlash("D:\Internet\ test2.txt"), true);


The backslash indicates the following character to be printed as is. In
this case you just have "D:Internettest2.txt". However, you may use
another web typical syntax with slashes:

fso.CreateTextFile(makeLocalePath("D:/Internet/test2.txt"), true);

function makeLocalePath(path) {
return path.replace(/\//g,"\\");
}

Daniel
Jul 19 '05 #12
I'm not doing it from code, I'm doing it with the help of a mouse....

I think Bob & Chris, in another branch of this thread, have explained that
what I was trying to do is actually impossible...

J
Jul 19 '05 #13
Thanks, Daniel.

JON
Jul 19 '05 #14
Daniel Kirsch <Iw*****************@gmx.de> writes:
Jon Maz wrote:
fso.CreateTextFile(DoubleUpBackSlash("D:\Internet\ test2.txt"), true);


The backslash indicates the following character to be printed as
is.


Actually, a backslash followed by another character together form an
"escape sequence", which stands for a single character. Some escape
sequences for non-printing characters are
\n - newline
\r - return
\t - tab
(there are more, but not many). For characters which are not defined
as part of a special escape sequence, the escape sequence just becomes
the second character itself.
In this case you just have "D:Internettest2.txt".


So, in this case, "\t" becomes a tab character, and you have:
"D:Internet est2.txt"
^ This is a tab character, ASCII 8.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 19 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Reply Via Newsgroup Thanks | last post by:
Folks, This questions is directed towards PHP/MySQL folk and relates to escaping hooks, apostraphe's and other characters that can create a security hole when writing to databases/files. I've...
2
by: BTnews | last post by:
Hi, Can anyone here point me at a definitive guide or tutorial about using escape characters when building SQL queries from user entered data? I'm especially interested in info on this in regard...
0
by: Hans | last post by:
Hi! Can someone explain how ASP works when it comes to unicode characters on the querystring? See the testcode below. If you type in a chinese character in the first textbox and click "post" the...
5
by: Henry | last post by:
I have this simple code, string escaped = Regex.Escape( @"`~!@#$%^&*()_=+{}\|;:',<.>/?" + "\"" ); string input = @"a&+" + "\"" + @"@(-d)\e"; Regex re = new Regex( string.Format(@"(+)", escaped),...
2
by: Pavils Jurjans | last post by:
Hello, I am looking fow C# equivalent of JavaScripts escape() and unescape() functions. I need to use C# function at the server side and then be able to use the opposite at the client side. ...
11
by: Geoff Caplan | last post by:
Hi folks, The thread on injection attacks was very instructive, but seemed to run out of steam at an interesting point. Now you guys have kindly educated me about the real nature of the issues,...
3
by: Arthur Dent | last post by:
Hello All... I am in an app that needs to write out an XML document for transmittal to an outside organization. All good and fine... I create the XmlDocument object, append all my nodes, and...
3
by: Taras_96 | last post by:
Hi everyone, I'm having a bit of trouble understanding the purpose of escaping nulls, and the use of addcslashes. Firstly, the manual states that: "Strictly speaking, MySQL requires only...
3
by: placid | last post by:
Hi All, I have these files; which are Merge Request (ClearCase) files that are created by a Perl CGI script (being re-written in Python, as the HTML/ JavaScript have been mixed with Perl,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.