Inserting Special Characters Problem

Inserting Special Characters Problem



Problem

You want to insert a special character, such as a line feed, into a string.

Solution

Use one of the escape sequences in the string.  use the escape sequence \u00A9:


var resultString = "This page \u00A9 Shelley Powers 

";
// print out to page 
var blk = document.getElementById("result"); 
blk.innerHTML = resultString;

EXPLAIN

The escape sequences in JavaScript all begin with the backslash character, (\). This char‐ acter signals the application processing the string that what follows is a sequence of characters that need special handling. lists the other escape sequences. 

The last three escape sequences in are patterns, where providing different numeric values will result in differing escape sequences. The copyright symbol in the solution is an example of the Unicode sequence pattern. 

The escape sequences listed in can also be represented as a Unicode se‐ quence. Unicode is a computing standard for consistent encoding, and a Unicode se‐ quence is a specific pattern for a given character. For instance, the horizontal tab (\t), can also be represented as the Unicode escape sequence, \u0009. Of course, if the user agent disregards the special character, as browsers do with the horizontal tab, the use is moot. One of the most common uses of escape sequences is to include double or single quotes within strings delimited by the same character: 

var newString = 'You can\'t use single quotes ' + 
 'in a string surrounded by single quotes.' + 
 'Oh, wait a sec...yes you can.';


0 comments:

Post a Comment