DHTML: TextDecoder.prototype.decode メソッド  編集:2022.01.16 by T.A.

実験的:これは実験的技術です。これを本番環境で使用する前に、ブラウザの互換性テーブルを注意深く確認してください。

その TextDecoder オブジェクトの特定のメソッドでデコードされた、パラメーターで指定されたテキストを含む DOMString を返します。→MS(en)

構文
string= decoder.decode([buffer[, options]])
decoder TextDecoder
buffer オプション デコードするテキストを含む ArrayBuffer または ArrayBufferView のいずれかです。
options オプション 次のプロパティを持つ TextDecodeOptions ディクショナリーです。
stream 後続の decode() の呼び出しで追加データが続くことを示す Boolean フラグ。データをチャンクで処理する場合は true に設定し、最後のチャンクまたはデータがチャンクされていない場合は false に設定します。デフォルトは false です。
戻り値

DOMString

この例では、ユーロ記号「€」をエンコードおよびデコードします。

HTML:

<p>Encoded value: <span id="encoded-value"></span></p>
<p>Decoded value: <span id="decoded-value"></span></p>

JavaScript:

const encoder = new TextEncoder();
const array = encoder.encode('€'); // Uint8Array(3) [226, 130, 172]
document.getElementById('encoded-value').textContent = array;

const decoder = new TextDecoder();
const str = decoder.decode(array); // String "€"
document.getElementById('decoded-value').textContent = str;

テスト
HTML:

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



スクリプト:


スクリプト:



表示内容:
表示内容: