Backslashes 
Author Message
 Backslashes

Hi everyone,

I'm afraid this is probably a newbie question.

I've written some javascript and it's working well. My first question is why
do I need to double up on Backslashes in string constants?

For example:

  Catalog = new ActiveXObject("ADOX.Catalog");
  Catalog.ActiveConnection =
    "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;" +
    "Data Source=D:\\Data\\BestRealty\\FOSMsg.mdb" ;

If I don't double up on backslashes in that last line, I get the following
error message:

D:\Scripts\AccessDbAdmin.js(18, 3) Microsoft JET Database Engine: Could not
find file 'D:\Scripts\DataBestRealtyFOSMsg.mdb'.

Does this have anything to do with running this on Windows 2000 Professional
or that the ActiveConnection is a property of a COM component?

It would seem the backslash is a special character. Are there others? Is
there a function I can use that will properly setup a string, so that I
don't have to manually double up backslashes?

I've read parts of the book "Windows Script Host" by Dino Esposito. But I
can't seem to find an answer to my question there.

Thanks for any assistance!!!

Richard Rogers
Toronto, Ontario
Canada.



Mon, 26 Apr 2004 00:28:00 GMT  
 Backslashes

In JScript, the backslash (\) is an "escape" character.

It is used to specify "special characters": http://msdn.microsoft.com/library/default.asp?url=/library/en-us/scri...

(make sure you get that whole URL in one piece and note that the resulting page can not be located through the navigation tree at the left!)

For example, "\t" means a horizontal tab (in this case, a specific value). It seems to me that "\n" (newline) SOMETIMES means a single carriage-return character, and SOMETIMES means "go to the next line even if we're in a GUI mode such as a dialog box"...

The trick for your purposes is that the backslash is ALWAYS the escape character, so that in "C:\Dirone\fileone.txt" "\D" will be taken as "D" (because "\D" is not a predefined special character), and "\f" will be taken as "Form feed", because it IS a predefined special character.

Therefore in "\\", the first backslash says "I'm the escape character", and the second backslash is, well, a backslash.

Enjoy, and if you're using the MSDN documentation, watch out for other pages that are no longer linked to the tree.

---Wayne Erfling

Quote:

> Hi everyone,

> I'm afraid this is probably a newbie question.

> I've written some javascript and it's working well. My first question is why
> do I need to double up on Backslashes in string constants?

> For example:

> Catalog = new ActiveXObject("ADOX.Catalog");
> Catalog.ActiveConnection =
> "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;" +
> "Data Source=D:\\Data\\BestRealty\\FOSMsg.mdb" ;

> If I don't double up on backslashes in that last line, I get the following
> error message:

> D:\Scripts\AccessDbAdmin.js(18, 3) Microsoft JET Database Engine: Could not
> find file 'D:\Scripts\DataBestRealtyFOSMsg.mdb'.

> Does this have anything to do with running this on Windows 2000 Professional
> or that the ActiveConnection is a property of a COM component?

> It would seem the backslash is a special character. Are there others? Is
> there a function I can use that will properly setup a string, so that I
> don't have to manually double up backslashes?

> I've read parts of the book "Windows Script Host" by Dino Esposito. But I
> can't seem to find an answer to my question there.

> Thanks for any assistance!!!

> Richard Rogers
> Toronto, Ontario
> Canada.


> Hi everyone,

> I'm afraid this is probably a newbie question.

> I've written some javascript and it's working well. My first question is why
> do I need to double up on Backslashes in string constants?

> For example:

>   Catalog = new ActiveXObject("ADOX.Catalog");
>   Catalog.ActiveConnection =
>     "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;" +
>     "Data Source=D:\\Data\\BestRealty\\FOSMsg.mdb" ;

> If I don't double up on backslashes in that last line, I get the following
> error message:

> D:\Scripts\AccessDbAdmin.js(18, 3) Microsoft JET Database Engine: Could not
> find file 'D:\Scripts\DataBestRealtyFOSMsg.mdb'.

> Does this have anything to do with running this on Windows 2000 Professional
> or that the ActiveConnection is a property of a COM component?

> It would seem the backslash is a special character. Are there others? Is
> there a function I can use that will properly setup a string, so that I
> don't have to manually double up backslashes?

> I've read parts of the book "Windows Script Host" by Dino Esposito. But I
> can't seem to find an answer to my question there.

> Thanks for any assistance!!!

> Richard Rogers
> Toronto, Ontario
> Canada.



Mon, 26 Apr 2004 00:50:01 GMT  
 Backslashes
That's very helpful Wayne,

Thanks a lot for the URL as well!!!

Richard.



Mon, 26 Apr 2004 01:07:33 GMT  
 Backslashes
By the way, if anyone uses the PathCopy context menu extension to help with
snagging system paths
http://home.worldonline.dk/~ninotech/freeutil.htm

You can configure it to do "custom" copying; I've done this to automatically
double embedded "\" marks for use with Jscript... Very handy.


Quote:
> That's very helpful Wayne,

> Thanks a lot for the URL as well!!!

> Richard.



Mon, 26 Apr 2004 03:38:33 GMT  
 Backslashes
Hi Alex,

Actually I'm a Delphi developer, and I developed a shell extension just like
that, which copies the folder/file name to the clipboard. Mine isn't quite
as advanced as that though.

I'm thinking of writing a function that may use the RegExp object to
properly configure a string in javascript. This way, if the user ends up
typing in a path (using the Prompt statement), I can still format it
properly.

Thanks for the tip.

Richard.



Mon, 26 Apr 2004 04:46:09 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Stop backslash behaving as the escape character

2. Backslash disapears

3. getting to read the backslash

4. Backslash problems - help!

5. How to print backslash?

6. Reading registry values containing a backslash (\)

7. double backslashes

8. Slash/Backslash, Absolute/Relative Path in FSO

9. using Registry functions on valuenames with backslashes?

10. Using Backslash with RegWrite

11. Regread with Backslash

12. escaping backslashes

 

 
Powered by phpBB® Forum Software