4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

サロゲートペア、異体字、絵文字に対応した文字数の数え方

Posted at

spread operatorだけでサロゲートペア文字列は対応できる

"𠮷野屋".length //=> 4
[..."𠮷野屋"].length // => 3

異体字や絵文字対応するなら、ライブラリを使う

import split from "graphemesplit";

"𠮷野屋👍🏾葛飾区👍葛󠄀城市👍🏿".length // => 22
[..."𠮷野屋👍🏾葛飾区👍葛󠄀城市👍🏿"].length // => 15
split("𠮷野屋👍🏾葛飾区👍葛󠄀城市👍🏿").length // => 12

使うライブラリ

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?