DOM

インターフェイス

TextDecoder インターフェイス

  編集:2022.02.12 by T.A.

MS

特定のテキストエンコーディング、例えば UTF-8、ISO-8859-2、KOI8-R、GBK、等のデコーダーを表します。デコーダーは入力としてバイトのストリームを取り、コード・ポイントのストリームを出力します。

コンストラクター
decoder= new TextDecoder([utfLabel[,options]])
新たに生成した TextDecoder を返します。これは、引数で指定したデコード方式を使用して連続したコード・ポイントを生成します。
プロパティ

TextDecoder インターフェイスは、何もプロパティを継承していません。

string= decoder.decoding 読取専用
デコーダーの名称を持つ DOMString であり、これは TextDecoder が使用する方式を表す文字列です。
boolean= TextDecoder.fatal読取専用
エラー・モードが fatal であるかを示す Boolean です。
boolean= TextDecoder.ignoreBOM読取専用
バイト・オーダー・マークを無視するかどうかを示す Boolean です。
メソッド

TextDecoder インターフェイスは、何もメソッドを継承していません。

string= decoder.decode([buffer[,options]])
特定の TextDecoder オブジェクトの方式でデコードされたテキストを含む DOMString を返します。
型付き配列でのテキスト表現
この例では、中国語/日本語の文字を、異なる 5 種類の型付き配列、Uint8ArrayInt8ArrayUint16ArrayInt16ArrayInt32Array で表します。
let utf8decoder = new TextDecoder(); // default 'utf-8' or 'utf8'

let u8arr = new Uint8Array([240, 160, 174, 183]);
let i8arr = new Int8Array([-16, -96, -82, -73]);
let u16arr = new Uint16Array([41200, 47022]);
let i16arr = new Int16Array([-24336, -18514]);
let i32arr = new Int32Array([-1213292304]);

console.log(utf8decoder.decode(u8arr));
console.log(utf8decoder.decode(i8arr));
console.log(utf8decoder.decode(u16arr));
console.log(utf8decoder.decode(i16arr));
console.log(utf8decoder.decode(i32arr));

テスト
HTML:

ここに表示
スクリプト組み込み:



スクリプト:


スクリプト:



表示内容:
表示内容: