0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

意図した文字の中身になっているか確認方法

0
Posted at

unicode

全世界共通で使えるように、世界中の文字を収録する文字コード規格。
コードポイントの数値で文字を表すための表記として、「U+16進数」という書き方を使う

コードポイントとは

文字に割り当てられた数字

UTF-8

ウェブで用いられるテキストファイル(hoge.html、piyo.css、fuga.js など)で一般的に使用される

UTF-16

JavaScript が内部で文字列を保持するのに使われる「文字コード(Character Encoding)」

UTF-32

テキストファイルで使用されることは少なく、主にシステムのメモリ上での管理や、符号位置の数で管理するデータベースなどで使用

意図した文字になっているか確認できる
(例)半角の数字か、全角の数字か

codePointAt

  • String 値のメソッド
  • 文字列の指定した位置にある文字のUnicodeコードポイントを取得
  • 文字列の最初の1文字目の位置は0
  • 引数が範囲外のときは、undefinedを返す
  • 10進数表記
文字列.codePointAt(インデックス)

記載例

console.log("あ".codePointAt(0));
//12354

String.fromCodePoint()

引数に指定したUnicodeコードポイントから文字列を作成して返す。

String.fromCodePoint(コードポイント[, ...[, コードポイント]])
console.log(String.fromCodePoint(12354));
//あ

参考文献

https://jsprimer.net/basic/string-unicode/
https://itsakura.com/javascript-codepointat
https://www.javadrive.jp/javascript/string/index14.html#google_vignette
https://www.buildinsider.net/language/csharpunicode/01/
https://techblog.kayac.com/unicode-code-point-vs-code-unit
https://ja.wikipedia.org/wiki/UTF-32
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt
https://www.javadrive.jp/javascript/string/index16.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?