📜  打字稿 | String charCodeAt() 方法

📅  最后修改于: 2022-05-13 01:56:24.834000             🧑  作者: Mango

打字稿 | String charCodeAt() 方法

charCodeAt()TypeScript中的一个内置函数,用于返回表示指定索引处字符的 Unicode 值的数字。
句法:

string.charCodeAt(index);

参数:此方法接受如上所述和下文所述的单个参数。

  • index该参数是一个小于字符串长度的 0 到 1 之间的整数。

返回值:此方法返回数字,指示给定索引处字符的 Unicode 值。

下面的例子说明了  TypeScriptJS 中的字符串 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);


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));


输出:

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