JavaScript言語の理由 (JavaScript言語の組み込み文字列サポート)ascii
そしてutf-16
暗号化できない文字列に出くわしたとき,ArrayBuffer
文字列パラメータを通過できるすべての API インターフェースは,ArrayBuffer
type.
これは次の例で簡単に説明できます.
function stringToHex(str) {
let hex = '';
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i).toString(16);
hex += charCode.length === 1 ? '0' + charCode : charCode;
}
return hex;
}
function main() {
const inputString = "abc𠮷123"; // The Unicode code point of the "𠮷" character is more than 16 bits.
// const inputString = "abcG123"; // If the abcG123 string test is used, the variable outputD is not assigned to ArrayBuffer
// Use the Encode function to encode inputString as hex.
const encodedHex = Encode("raw", "string", "hex", inputString);
Log(encodedHex); // Contents for: 61 62 63 f0a0aeb7 31 32 33
// Use your own implementation of the stringToHex function to encode, due to the inability to deal with the "𠮷" character, resulting in an error in the hex encoding.
const manuallyEncodedHex = stringToHex(inputString);
Log(manuallyEncodedHex); // Contents for: 61 62 63 d842dfb7 31 32 33
// Successful reduction from hex code to string (variable inputString)
const decodedString = Encode("raw", "hex", "string", encodedHex);
Log(decodedString);
// Unable to decode, returns ArrayBuffer, i.e. variable outputD is ArrayBuffer
const outputD = Encode("raw", "hex", "string", manuallyEncodedHex);
Log(outputD);
// Validate the returned ArrayBuffer type variable outputD
const bufferD = new Uint8Array(outputD);
let hexBufferD = '';
for (let i = 0; i < bufferD.length; i++) {
hexBufferD += bufferD[i].toString(16).padStart(2, '0');
}
Log(hexBufferD); // 61 62 63 d842dfb7 31 32 33
}
C++ 戦略 書き込み 指示
ウェブ3