Replaces each markup-significant character in a string with its corresponding character entity.

Syntax

JSV_toCharacterEntity(expS)

Prototype

expS.toCharacterEntity()

Returns

Returns the string expS, with every occurrence of the markup-significant characters replaced by its corresponding character entity.

Parameters

The toCharacterEntity function uses the following arguments.

Argument Description
expS The string that is to be converted.

Remarks

The markup-significant characters and their corresponding character entity are:

Markup-Significant
Character
  Character
Entity
&   &
<   &lt;
>   &gt;
"   &quot;

See the Web Design Group HTML 4.0 Reference on Special Entities for more information.

If you should modify the function to include more of the markup-significant characters, be sure that &amp; is the first markup-significant character to be replaced. Note that the list of strings to be replaced is processed one after another. In this way you may experience recursive replacement if one of the latter elements is contained in any of the earlier elements. For example, you may end up replacing the & in the other markup-significant characters (e.g., &gt;) if & is placed latter in the list rather than first.

Dependencies

JSV_isWhitespace, JSV_replace

Example

The following lines of code

var myString = 
    'Everyone should visit ' + 
    '<A HREF="http://www.irt.org/index.htm">irt.org</A> ' +
    'at least once in their life.';
document.write( JSV_toCharacterEntity(myString) );

produce



The string myString is: