fromcharcode
字符串fromCharCode()方法 (String fromCharCode() Method)
fromCharCode() Method is a string method in JavaScript, it is used to get the character from the given Unicode(s). By using this function, we can get the characters from the given Unicode’s. Here, we can pass multiple numbers to get their corresponding characters.
fromCharCode()方法是JavaScript中的字符串方法,用于从给定的Unicode获取字符。 通过使用此功能,我们可以从给定的Unicode字符中获取字符。 在这里,我们可以传递多个数字以获取其对应的字符。
Note: We can also provide the number in octal (following by 0) and hexadecimal format (following by 0x).
注意:我们还可以提供八进制数(紧随其后的0 )和十六进制格式(紧随其后的0x )的数字。
Syntax:
句法:
String.fromCharCode(number1, number2, number2, ...);
It accepts one or more numbers (Unicode), and returns the characters of them.
它接受一个或多个数字(Unicode),并返回它们的字符。
Examples:
例子:
Function call:
String.fromCharCode(65);
Output:
"A"
Function call:
String.fromCharCode(65, 66);
Output:
"AB"
Code:
码:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
//passing values in decimal
document.write(String.fromCharCode(65) + "<br>");
document.write(String.fromCharCode(65, 66) + "<br>");
document.write(String.fromCharCode(65, 66, 67) + "<br>");
document.write(String.fromCharCode(72, 69, 76, 76, 79) + "<br>");
//passing values in octal
document.write(String.fromCharCode(0101) + "<br>");
document.write(String.fromCharCode(0101, 0102) + "<br>");
document.write(String.fromCharCode(0101, 0102, 0103) + "<br>");
document.write(String.fromCharCode(0110, 0105, 0114, 0114, 0117) + "<br>");
//passing values in hexadecimal
document.write(String.fromCharCode(0x41) + "<br>");
document.write(String.fromCharCode(0x41, 0x42) + "<br>");
document.write(String.fromCharCode(0x41, 0x42, 0x43) + "<br>");
document.write(String.fromCharCode(0x48, 0x45, 0x4C, 0x4C, 0x4F) + "<br>");
</script>
</body>
</html>
Output
输出量
A
AB
ABC
HELLO
A
AB
ABC
HELLO
A
AB
ABC
HELLO
翻译自: https://www.includehelp.com/code-snippets/string-fromCharCode-method-with-example-in-javascript.aspx
fromcharcode