encode
for strings
Encode a string into bytes.
Signature
> encode {flags} (encoding)
Flags
--ignore-errors, -i
: when a character isn't in the given encoding, replace with a HTML entity (like🎈
)
Parameters
encoding
: The text encoding to use.
Input/output types:
input | output |
---|---|
string | binary |
Examples
Encode an UTF-8 string into Shift-JIS
> "負けると知って戦うのが、遥かに美しいのだ" | encode shift-jis
Length: 40 (0x28) bytes | printable whitespace ascii_other non_ascii
00000000: 95 89 82 af 82 e9 82 c6 92 6d 82 c1 82 c4 90 ed ×××××××××m××××××
00000010: 82 a4 82 cc 82 aa 81 41 97 79 82 a9 82 c9 94 fc ×××××××A×y××××××
00000020: 82 b5 82 a2 82 cc 82 be ××××××××
Replace characters with HTML entities if they can't be encoded
> "🎈" | encode --ignore-errors shift-jis
Length: 9 (0x9) bytes | printable whitespace ascii_other non_ascii
00000000: 26 23 31 32 37 38 38 30 3b 🎈
Notes
Multiple encodings are supported; here are a few: big5, euc-jp, euc-kr, gbk, iso-8859-1, cp1252, latin5
Note that since the Encoding Standard doesn't specify encoders for utf-16le and utf-16be, these are not yet supported. More information can be found here: https://docs.rs/encoding_rs/latest/encoding_rs/#utf-16le-utf-16be-and-unicode-encoding-schemes
For a more complete list of encodings, please refer to the encoding_rs documentation link at https://docs.rs/encoding_rs/latest/encoding_rs/#statics
Subcommands:
name | description | type |
---|---|---|
encode base32 | Encode a string or binary value using Base32. | built-in |
encode base32hex | Encode a binary value or a string using base32hex. | built-in |
encode base64 | Encode a string or binary value using Base64. | built-in |
encode hex | Hex encode a binary value or a string. | built-in |