If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.
Use the String. replaceAll() method to remove all double quotes from a string, e.g. str. replaceAll('"', '') . The replace() method will return a new string with all double quotes removed.
This variant -
<a title="Some "text"">Hover me</a>
Is correct and it works as expected - you see normal quotes in rendered page.
Here's a snippet of the HTML escape characters taken from a cached page on archive.org:
< | < less than sign
@ | @ at sign
] | ] right bracket
{ | { left curly brace
} | } right curly brace
… | … ellipsis
‡ | ‡ double dagger
’ | ’ right single quote
” | ” right double quote
– | – short dash
™ | ™ trademark
¢ | ¢ cent sign
¥ | ¥ yen sign
© | © copyright sign
¬ | ¬ logical not sign
° | ° degree sign
² | ² superscript 2
¹ | ¹ superscript 1
¼ | ¼ fraction 1/4
¾ | ¾ fraction 3/4
÷ | ÷ division sign
” | ” right double quote
> | > greater than sign
[ | [ left bracket
` | ` back apostrophe
| | | vertical bar
~ | ~ tilde
† | † dagger
‘ | ‘ left single quote
“ | “ left double quote
• | • bullet
— | — longer dash
¡ | ¡ inverted exclamation point
£ | £ pound sign
¦ | ¦ broken vertical bar
« | « double left than sign
® | ® registered trademark sign
± | ± plus or minus sign
³ | ³ superscript 3
» | » double greater-than sign
½ | ½ fraction 1/2
¿ | ¿ inverted question mark
“ | “ left double quote
— | — dash
The escape code "
can also be used instead of "
.
Using "
is the way to do it. I tried your second code snippet, and it works in both Firefox and Internet Explorer.
It may work with any character from the HTML Escape character list, but I had the same problem with a Java project. I used StringEscapeUtils.escapeHTML("Testing \" <br> <p>")
and the title was <a href=".." title="Test" <br> <p>">Testing</a>
.
It only worked for me when I changed the StringEscapeUtils to StringEscapeUtils.escapeJavascript("Testing \" <br> <p>")
and it worked in every browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With