fromcharcode_字符串fromCharCode()方法,带有JavaScript中的示例

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值