473,574 Members | 5,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DoubleUpBackSla sh(inputString)
{
???????
}

which will do the following:

<%
var inputString = "D:\Internet\te st2.txt"
Response.Write( DoubleUpBackSla sh(inputString) );
%>

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

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

TIA,

JON

Jul 19 '05 #1
14 3527
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****@surfeuN OSPAM.de> wrote in message
news:Oo******** ******@tk2msftn gp13.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 DoubleUpBackSla sh(inputString)
{
???????
}

which will do the following:

<%
var inputString = "D:\Internet\te st2.txt"
Response.Write( DoubleUpBackSla sh(inputString) );
%>

...printing out the following on the screen:
D:\\Internet\\t est2.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.CreateOb ject("Scripting .FileSystemObje ct");

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

//works
var wfile = fso.CreateTextF ile(" D:\\Internet\\t est2.txt", true);

//want this to work!
var wfile =
fso.CreateTextF ile(DoubleUpBac kSlash("D:\Inte rnet\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****@surfeuN OSPAM.de> wrote in message
news:Op******** ******@TK2MSFTN GP09.phx.gbl...
Hi Ray,

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

<%
var fso = Server.CreateOb ject("Scripting .FileSystemObje ct");

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

//works
var wfile = fso.CreateTextF ile(" D:\\Internet\\t est2.txt", true);

//want this to work!
var wfile =
fso.CreateTextF ile(DoubleUpBac kSlash("D:\Inte rnet\test2.txt" ), true);

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

Thanks,

JON


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

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

<%
var fso = Server.CreateOb ject("Scripting .FileSystemObje ct");

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

//works
var wfile = fso.CreateTextF ile(" D:\\Internet\\t est2.txt", true);

//want this to work!
var wfile =
fso.CreateTextF ile(DoubleUpBac kSlash("D:\Inte rnet\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.CreateOb ject("Scripting .FileSystemObje ct");

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

//works
var wfile = fso.CreateTextF ile(" D:\\Internet\\t est2.txt", true);

//want this to work!
var wfile =
fso.CreateTextF ile(DoubleUpBac kSlash("D:\Inte rnet\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******** ********@TK2MSF TNGP15.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

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

Similar topics

0
1978
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 been reading http://ca2.php.net/manual/en/function.get-magic-quotes-gpc.php and just need to confirm a couple of things: If I have magic_quotes_gpc...
2
8531
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 to Access databases and (classic) ASP. I've been writing ASP for just over a year now, and I've usually found very comprehensive answers to...
0
2027
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 javascript code will change the action for the <form> and add the text entered in the first editbox to the querystring and then submit the form....
5
2312
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), RegexOptions.CultureInvariant ); string s = re.Replace( input, "" ); It doesn't seem to work, regular expression return without filter out any...
2
14470
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. JavaScripts escape() function converts all non-alphanumerical chars to %xx, and all unicode chars to %uxxxx (where xxxx is unicode charcode). I'd like...
11
2165
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, can I ask again what effective escaping really means? Are the standard escaping functions found in the PHP, Tcl etc APIs to Postgres bombproof?...
3
3151
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 values etc etc... and it all works. Now I go to save the file... I tried two methods... MyXmlDocument.Save(filename) and...
3
5370
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 that backslash and the quote character used to quote the string in the query be escaped. This function quotes the other characters to make them easier...
3
3370
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, maintainability is zero) MergeType::::codefromlabel:::: BLname::::BUILDMODS:::: OldLname:::::::: BaseVersion::::6.9.1.24A::::
0
7738
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8079
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8258
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5321
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3756
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3770
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.