当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Typescript String charCodeAt()用法及代码示例


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

相关用法


注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 TypeScript | String charCodeAt() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。