Javascript HELP!!

cowasaki

TPer Emeritus
Suspended / Banned
Messages
19,708
Name
Darren
Edit My Images
Yes
Ok in BASIC we have CHR$(34) for a speach mark "

in pascal we use CHR(34) or """

in assembly language we just use 34

how do I test if a string is equal to a speach mark in JAVASCRIPT ??????

ie

if (st = ????) {do something};

where st is the string that might contain a speach mark
and ???? is the bit I do not know.....

I urgently need this for the user interface version of the user data.lib editor for the script thingy :)
 
Take a look here. I have a feeling that if you want to compare the html code, if it's standards compliant then you'll be needing those special character codes.
 
I was also thinking, if the string is coming in from a form then it might be escaped, in which case you'll need to take that into account. Also, have you tried using a regular expression?
 
No I just need the character " in a string variable. At the moment I have created a textfile containing just a " which I read into the variable in order to check. I have got the program to pull the variables from the USER DATE.lib file and display them on the screen so just need to do the function to write back but it would be tidier if I could find the equivalent of...


var quote = " (this does not actually work !)


Oh very funny :) I type & # 3 4 (minus the spaces) and it changes it to the char I actually want!
 
To check if it is a quote in JS you can just do (for example);

Code:
var the_quote = '"';
if (the_quote == '"') {
    alert("Match");
}

JS allows you to use either double or single quotes to specify a string so you can just wrap a single double quote in single quotes.

If you are using double quotes to specify strings, for consistency you can just escape the double quote in the middle of the string, e.g.

Code:
"\""

Hope this is what you were looking for.
 
To check if it is a quote in JS you can just do (for example);

Code:
var the_quote = '"';
if (the_quote == '"') {
    alert("Match");
}

JS allows you to use either double or single quotes to specify a string so you can just wrap a single double quote in single quotes.

If you are using double quotes to specify strings, for consistency you can just escape the double quote in the middle of the string, e.g.

Code:
"\""

Hope this is what you were looking for.

Thanks, I am used to programming other languages. I always have problems when I start a new language as you cannot get books on syntax etc which don't treat you like you are new to programming!

ADDED: In fact that helps even more with another section of the script too!
 
Back
Top