• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. Strings > 1.10. Converting Between Unicode Values and String Characters

Converting Between Unicode Values and String Characters

NN 2, IE 3

Problem

You want to obtain the Unicode code number for an alphanumeric character or vice versa.

Solution

To obtain the Unicode value of a character of a string, use the charCodeAt( ) method of the string value. A single parameter is an integer pointing to the zero-based position of the character within the string:

var code = myString.charCodeAt(3);

If the string consists of only one character, use the 0 argument to get the code for that one character:

var oneChar = myString.substring(12, 13);
var code = oneChar.charCodeAt(0);

The returned value is an integer.

To convert an Unicode code number to a character, use the fromCharCode( ) method of the static String object:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint