简介:
String对象允许你处理一系列字符;它用许多辅助方法包装Javascript的字符串原始数据类型。当JavaScript在字符串原语和字符串对象之间自动转换时,可以在字符串原语上调用string对象的任何辅助方法。本文主要介绍JavaScript(JS) string.charCodeAt(index) 方法。
1、描述
此方法返回指示给定索引处的字符的Unicode
值的数字。
Unicode Code
点的范围从0到1,114,111。第一128个Unicode代码点是ASCII字符编码的直接匹配。 charCodeAt()
始终返回小于65,536的值。
2、语法
使用以下语法查找特定索引处的字符代码:
string.charCodeAt(index);
3、参数
index:0
到1
之间的整数小于字符串的长度; 如果未指定,则默认为0
。
4、返回值
返回指示给定索引处的字符的Unicode值的数字。如果给定的索引不在0到1之间的介于0到1之间,则返回NaN
。
5、使用示例
<html>
<head>
<title>JavaScript String charCodeAt() Method</title>
</head>
<body>
<script type = "text/javascript">
var str = new String( "This is string" );
document.write("str.charCodeAt(0) is:" + str.charCodeAt(0));
document.write("<br />str.charCodeAt(1) is:" + str.charCodeAt(1));
document.write("<br />str.charCodeAt(2) is:" + str.charCodeAt(2));
document.write("<br />str.charCodeAt(3) is:" + str.charCodeAt(3));
document.write("<br />str.charCodeAt(4) is:" + str.charCodeAt(4));
document.write("<br />str.charCodeAt(5) is:" + str.charCodeAt(5));
</script>
</body>
</html>
6、输出
str.charCodeAt(0) is:84
str.charCodeAt(1) is:104
str.charCodeAt(2) is:105
str.charCodeAt(3) is:115
str.charCodeAt(4) is:32
str.charCodeAt(5) is:105
了解更多分析及数据抓取可查看:
http://data.yisurvey.com:8989/
特别说明:本文旨在技术交流,请勿将涉及的技术用于非法用途,否则一切后果自负。如果您觉得我们侵犯了您的合法权益,请联系我们予以处理。