Intl.Segmenter.prototype.segment()
Baseline 2024Newly available
Since April 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Intl.Segmenter.prototype.segment()
メソッドは、この Intl.Segmenter
オブジェクトのロケールおよび粒度に従って文字列を分割します。
試してみましょう
構文
js
segment(input);
引数
返値
入力文字列のセグメントを含む、反復可能な新しい Segments
オブジェクトです。
例
js
// ロケール固有の単語分割器を生成する
const segmenter = new Intl.Segmenter("fr", { granularity: "word" });
// それを用い、文字列のセグメントを走査するイテレーターを取得する
const input = "Moi ? N'est-ce pas ?";
const segments = segmenter.segment(input);
// それを用い、分割を行う
for (const { segment, index, isWordLike } of segments) {
console.log(
"segment at code units [%d, %d]: «%s»%s",
index,
index + segment.length,
segment,
isWordLike ? " (word-like)" : "",
);
}
// logs
// segment at code units [0, 3]: «Moi» (word-like)
// segment at code units [3, 4]: « »
// segment at code units [4, 5]: «?»
// segment at code units [5, 6]: « »
// segment at code units [6, 11]: «N'est» (word-like)
// segment at code units [11, 12]: «-»
// segment at code units [12, 14]: «ce» (word-like)
// segment at code units [14, 15]: « »
// segment at code units [15, 18]: «pas» (word-like)
// segment at code units [18, 19]: « »
// segment at code units [19, 20]: «?»
仕様書
Specification |
---|
ECMAScript® 2025 Internationalization API Specification # sec-intl.segmenter.prototype.segment |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
segment |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.