473,657 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Backslash confusion

I have to pass the string '\abcd' to a function. Ofcourse one (or two) extra
'\' is needed to escape but experimenting with it shows that I have to pass
three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex(q) ;
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?
Jun 27 '08 #1
4 1362
freelance71 schreef:
I have to pass the string '\abcd' to a function. Ofcourse one (or two) extra
'\' is needed to escape but experimenting with it shows that I have to pass
three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex(q) ;
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?

I do not understand.
Your script alerts \\abcd over here (on FF), as expected.
There must be more to it than you describe.

Regards,
Erwin Moller
Jun 27 '08 #2

"Erwin Moller"
<Si************ *************** *************** @spamyourself.c omwrote in
message news:48******** *************** @news.xs4all.nl ...
freelance71 schreef:
>I have to pass the string '\abcd' to a function. Ofcourse one (or two)
extra '\' is needed to escape but experimenting with it shows that I have
to pass three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex(q );
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?

I do not understand.
Your script alerts \\abcd over here (on FF), as expected.
There must be more to it than you describe.

Regards,
Erwin Moller

can it be because I'm using it in a PHP file like this?

<?php

echo <<< HTMLOUT

<script>

var q = '\\\\abcd';

displayLatex(q) ;

</script>

HTMLOUT;

?>
Jun 27 '08 #3
freelance71 schreef:
"Erwin Moller"
<Si************ *************** *************** @spamyourself.c omwrote in
message news:48******** *************** @news.xs4all.nl ...
>freelance71 schreef:
>>I have to pass the string '\abcd' to a function. Ofcourse one (or two)
extra '\' is needed to escape but experimenting with it shows that I have
to pass three extra backslashes to make it work.

<script>
var q = "\\\\abcd";
displayLatex( q);
</script>
/* this function is in another file */

function displayLatex(q) {
alert(q); /* this shows \abcd when called by above script*/

}
Can anyone explain why this is so? why 4 backslashes?
I do not understand.
Your script alerts \\abcd over here (on FF), as expected.
There must be more to it than you describe.

Regards,
Erwin Moller


can it be because I'm using it in a PHP file like this?
Yes. That is the reason.
>
<?php

echo <<< HTMLOUT

<script>

var q = '\\\\abcd';
that becomes:
var q = '\\abcd';

in your HTML.
Simply check your source in your browser to see it.

Regards,
Erwin Moller
>
displayLatex(q) ;

</script>

HTMLOUT;

?>

Jun 27 '08 #4
freelance71 wrote:
>freelance71 schreef:
>>I have to pass the string '\abcd' to a function. Ofcourse one (or two)
extra '\' is needed to escape but experimenting with it shows that I have
to pass three extra backslashes to make it work.
[...]
can it be because I'm using it in a PHP file like this?

<?php

echo <<< HTMLOUT

<script>

var q = '\\\\abcd';

displayLatex(q) ;

</script>

HTMLOUT;

?>
Yes, you have to escape each backslash for use with `echo'. A simple test
(with php -a) shows that

<?php

echo <<<HTML

var q = '\\a';

HTML;

?>

displays only one backslash.

The simple and most efficient solution is to take heed of this general
advice: Do not let the PHP parser do things it does not have to.

<?php
...
?>
var q = '\\a';
<?php
...
?>

(The first and last part are optional, of course.)
F'up2 cl.php

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #5

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

Similar topics

5
6902
by: Aloysio Figueiredo | last post by:
I need to replace every ocurrence of '/' in s by '\/' in order to create a file named s. My first attempt was: s = '\/'.join(s.split('/')) but it doesn't work: >>> s = 'a/b' >>> s = '\/'.join(s.split('/'))
3
22227
by: Terry Asher | last post by:
The following script does NOT escape the Apostrophe. Meaning when you mouseover the image the Alt tag says this: DMACC, It and then it stops. <SCRIPT Language="JavaScript"> var pos = "DMACC, It\'s the Smart Thing to Do."; document.write("<img name=img5 id=img5 src='/homepage/dmaccstudent" + Math.floor(Math.random() *20) + ".jpg' WIDTH=145 HEIGHT=230 border=0 ALT='"+pos+"'>"); </SCRIPT>
19
6325
by: Alan J. Flavell | last post by:
The story so far: on somewhat unrelated newsgroup, my attention fell upon the URL: http://www.speedtouchdsl.com/prod706.htm which contains a link to the purported URL: http://www.speedtouchdsl.com/pdf\datasheet706WL-780WL.pdf Comparing the latter with other URLs in that area, it appeared that the "\" was a probable blunder for "/". However, since their web server is IIS, it appears that their server silently fixes-up this blunder, and...
2
3238
by: John Dann | last post by:
I guess there must be some convention or Windows specification for whether the backslash immediately preceding the file name in a full path string to a file is formally part of the path string or of the file name. I suppose the options are: 1. Part of the path string, ie all returned path strings should have a trailing backslash. 2. Part of the file name, ie all file names should start with a backslash.
3
22976
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code) replaced, but the second is not ??? Is it in general better to use double backslash in filepaths ? thanks, Stef Mientki
2
2167
by: Tobiah | last post by:
>>"'" "'" "'" "\\'" "\\'" This is quite different than any other language that I am used to. Normally, a double backslash takes away the special meaning of the last backslash, and so you are left with a single backslash.
5
15674
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular number 040? Is it a decimal number from the ASCII code chart? (compiling using gcc on SunOS 5.8, Sparc, Ultra-80) Just curious. Thanks.
4
2271
by: Razzbar | last post by:
I'm working on a bookmarklet that grabs information from a page and submits it to a server. Yet another social bookmarking application. I'm having trouble with page titles that include an apostrophe. I'm using encodeURIComponent() around the page title, and again around the URL. Apparently the browser is inserting a backslash before any apostrophe. I can see that when I write the $_GET data to a file in PHP on the server. When the GET...
4
3613
nithinpes
by: nithinpes | last post by:
I will boil down my exact requirement to this: I should print out lines that do not contain semi-colon, backslash and closing parentheses. The following one -liner works fine. perl -ne "unless(//) {print}" in.txt > out.txt Consider the following sample data: Msg_create(….); \ PSLogI18N\ Free( ….)
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.