JavaScript Special Characters
In JavaScript you can add special characters to a text string by using the backslash sign.
Insert Special Characters
The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.
Look at the following JavaScript code:
var txt="We are the so-called "Vikings" from the north.";
document.write(txt); |
In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called
To solve this problem, you must place a backslash (\) before each double quote in "Viking". This turns each double quote into a string literal:
var txt="We are the so-called \"Vikings\" from the north.";
document.write(txt); |
JavaScript will now output the proper text string: We are the so-called "Vikings" from the north.
Here is another example:
| document.write ("You \& I are singing!"); |
The example above will produce the following output:
The table below lists other special characters that can be added to a text string with the backslash sign:
| Code |
Outputs |
| \' |
single quote |
| \" |
double quote |
| \& |
ampersand |
| \\ |
backslash |
| \n |
new line |
| \r |
carriage return |
| \t |
tab |
| \b |
backspace |
| \f |
form feed |

Need an easy way to get data into XML, or transform XML to another format?
MapForce lets you map XML data to/from any combination of XML, database, flat file, Excel 2007, XBRL, or Web services data.
Then it transforms data instantly or auto-generates royalty-free data integration code for recurrent conversions.
New features in Version 2010!
Download a free, fully functional 30-day trial to experience the following features:
- Easy-to-use, graphical data mapping interface
- Instant data transformation
- XSLT 1.0/2.0 and XQuery code generation
- Java, C#, and C++ code generation
- Advanced data processing functions
- Support for all major relational databases including SQL Server, IBM DB2, Oracle, and more
- Visual Studio & Eclipse integration
Download a fully-functional trial today!
|
|
|
|