charCodeAt()是TypeScript中的内置函数,用于返回指示指定索引处字符的Unicode值的数字。句法:
string.charCodeAt(index);
参数:该方法接受上面提到和下面描述的单个参数。
- index 此参数是小于字符串长度的0到1之间的整数。
返回值:此方法返回数字,该数字指示给定索引处字符的Unicode值。
下面的示例说明TypeScriptJS中的String charCodeAt()方法:
范例1:
的JavaScript
var str = new String("JavaScript is object oriented language");
// Finding number indicating the Unicode value
// of the character at the given index
var value = str.charCodeAt(14);
console.log(value);
输出:
111
范例2:
的JavaScript
var str = new String('JavaScript is object oriented language');
// Finding number indicating the Unicode value
// of the character at the given index
console.log("Character at 0 is:" + str.charCodeAt(0));
console.log("Character at 1 is:" + str.charCodeAt(1));
输出:
Character at 0 is:74 Character at 1 is:97
相关用法
- Typescript String charAt()用法及代码示例
- Typescript String concat()用法及代码示例
- Typescript String indexOf()用法及代码示例
- Typescript String lastIndexOf()用法及代码示例
- Typescript String localeCompare()用法及代码示例
- Typescript String replace()用法及代码示例
- Typescript String search()用法及代码示例
- Typescript String slice()用法及代码示例
- Typescript String substring()用法及代码示例
- Typescript String valueOf()用法及代码示例
- Typescript String toString()用法及代码示例
- Typescript String toUpperCase()用法及代码示例
- Typescript String toLowerCase()用法及代码示例
- Typescript String toLocaleUpperCase()用法及代码示例
- Typescript String toLocaleLowerCase()用法及代码示例
- Typescript String substr()用法及代码示例
- Typescript String split()用法及代码示例
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 TypeScript | String charCodeAt() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。