Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Escaping escape characters in JScript

Reply
Thread Tools

Escaping escape characters in JScript

 
 
Jon Maz
Guest
Posts: n/a
 
      09-14-2004
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



 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      09-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Jon Maz
Guest
Posts: n/a
 
      09-14-2004
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





 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      09-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>
>



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      09-14-2004
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.


 
Reply With Quote
 
Chris Hohmann
Guest
Posts: n/a
 
      09-14-2004
"Jon Maz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Jon Maz
Guest
Posts: n/a
 
      09-14-2004
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


 
Reply With Quote
 
Jon Maz
Guest
Posts: n/a
 
      09-14-2004
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


 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      09-14-2004
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" <(E-Mail Removed)> wrote in message
news:e5H%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Jon Maz
Guest
Posts: n/a
 
      09-14-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Escaping escape characters in variables (in regexs) johnnykimble@gmail.com Perl Misc 8 06-27-2006 08:36 PM
What is Server-Side Jscript (not Jscript.NET)? Maxwell2006 ASP .Net 5 03-07-2006 05:28 AM
JScript.Net (JScript 7.0) is official documented language VK Javascript 4 01-12-2006 06:48 PM
Porting from JScript to JScript.Net - compiler error Jon Maz ASP .Net 4 09-09-2004 10:24 AM
Which to Learn: Javascript, Jscript, JScript.NET, ECMA 262 (3rd ed)? John Bentley Javascript 14 02-05-2004 06:14 PM



Advertisments