Typescript-string-charcodeat
提供:Dev Guides
TypeScript-文字列charCodeAt()
このメソッドは、指定されたインデックスにある文字のUnicode値を示す数値を返します。 Unicodeコードポイントの範囲は0〜1,114,111です。 最初の128個のUnicodeコードポイントは、ASCII文字エンコードの直接一致です。 charCodeAt()は常に65,536未満の値を返します。
構文
string.charCodeAt(index);
引数の詳細
インデックス-文字列の長さよりも小さい0から1の間の整数。指定しない場合、デフォルトは0です。
戻り値
指定されたインデックスにある文字のUnicode値を示す数値を返します。 指定されたインデックスが文字列の長さよりも0〜1の間でない場合は、 NaN を返します。
例
var str = new String("This is string");
console.log("str.charAt(0) is:" + str.charCodeAt(0));
console.log("str.charAt(1) is:" + str.charCodeAt(1));
console.log("str.charAt(2) is:" + str.charCodeAt(2));
console.log("str.charAt(3) is:" + str.charCodeAt(3));
console.log("str.charAt(4) is:" + str.charCodeAt(4));
console.log("str.charAt(5) is:" + str.charCodeAt(5));
コンパイル時に、JavaScriptで同じコードが生成されます。
その出力は次のとおりです-
str.charAt(0) is:84
str.charAt(1) is:104
str.charAt(2) is:105
str.charAt(3) is:115
str.charAt(4) is:32
str.charAt(5) is:105