Last active
April 20, 2024 07:16
-
-
Save sheepla/b9d2b868c6407099825fb06512a0856f to your computer and use it in GitHub Desktop.
日本語の文字数をカウントする.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://zenn.dev/pandanoir/articles/how-to-count-strings | |
function countStringLength(text:string) : number { | |
const segmenter = new Intl.Segmenter("ja-JP", { granularity: "grapheme" }) | |
const segments = [...segmenter.segment(text)] | |
console.log(segments) | |
return segments.length | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment