W3cubDocs

/Nushell

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

>"負けると知って戦うのが、遥かに美しいのだ"|encodeshift-jis
Length:40 (0x28) bytes|printablewhitespaceascii_othernon_ascii
00000000:958982af82e982c6926d82c182c490ed×××××××××m××××××
00000010:82a482cc82aa8141977982a982c994fc×××××××A×y××××××
00000020:82b582a282cc82be××××××××

Replace characters with HTML entities if they can't be encoded

>"🎈"|encode-ishift-jis
Length:9 (0x9) bytes|printablewhitespaceascii_othernon_ascii
00000000:26233132373838303b🎈

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.

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 type usage
encode base64 Builtin Encode a string or binary value using Base64.
encode hex Builtin Encode a binary value using hex.

Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/encode.html