fromCharCode and charCodeAt Methods _ basic knowledge

Source: Internet
Author: User
Returns a string from some Unicode character values.

String.fromCharCode ([code1[, code2[, ...) [, Coden]]]

Parameters
String

Required option. is a String object.

Code1, ..., coden

Options available. is the sequence of Unicode character values to convert to a string. If no arguments are given, the result is an empty string.

Description
You do not have to create a String object before calling fromCharCode.

In the following example, test contains the string "plain":

var test = String.fromCharCode (112, 108, 97, 105, 110);
charCodeAt method
Returns an Integer that represents the Unicode encoding of the character at the specified position.

strobj.charcodeat (Index)

Parameters
Strobj

Required option. Any String object or text.

Index

Required option. The number of the zero-based count of the character to be processed. A number with a valid value of 0 to a string length minus 1.

Description
The first character in a string is numbered 0, the second character is numbered 1, and so on.

If there are no characters at the specified location, NaN is returned.

Example
The following example illustrates the use of the charCodeAt method.

function Charcodeattest (n) {
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Initializes the variable.
var n; Declare a variable.
n = str.charcodeat (n-1); Gets the Unicode value of the character on position N.
return (n); Returns the value.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.