-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangle
committed
Jul 24, 2023
1 parent
025edff
commit 3dd08b0
Showing
5 changed files
with
455 additions
and
92 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//string to utf8 | ||
function strToUtf8Bytes(text) { | ||
const code = encodeURIComponent(text) | ||
const bytes = [] | ||
for (let i = 0;i < code.length;i++) { | ||
const c = code.charAt(i) | ||
if (c === '%') { | ||
const hex = code.charAt(i + 1) + code.charAt(i + 2) | ||
const hexval = parseInt(hex, 16) | ||
bytes.push(hexval) | ||
i += 2 | ||
} else { | ||
bytes.push(c.charCodeAt(0)) | ||
} | ||
} | ||
return bytes | ||
} | ||
|
||
console.log(strToUtf8Bytes('达摩克利斯之剑')) |
Binary file not shown.
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
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
Oops, something went wrong.