charCodeAt()

The charCodeAt() method is used to return the character encoding of the character which is at the place specified by number (see syntax). The count for the number of characters begins at the left most place within the string which is being searched. The first position is zero, the next is one, and so on. If the given number is not valid for that string, a value of -1 is returned. An example of this would be when you're asking for the character encoding at position 20 when the string is only 15 characters long. The character encoding values returned are based on the ISO-Latin-1 character encoding schema.

syntax:

stringName.charCodeAt(number)

EXAMPLE

var stringToSearch = new String("This is the string to search");

document.write("The character encoding of place six (small s ) is : " + stringToSearch.charCodeAt(6) )

The example shows the creation of a new string, called stringToSearch. A document.write statement then writes some descriptive text along with the character encoding of place 6 within the string. Place 6 is a lower case letter s. The returned value should look like the following:



The character encoding of place six (small s ) is : 115