Skip to content

Encode/Decode Methods

Base64 Encoding

Base64 is a binary-to-text encoding scheme that is used to transmit binary data over channels the only reliably support text content. Among Base64's uses are:

  • Embed images or other binary assets in HTML files.
  • Encode user credentials for HTTP Basic Authentication

Base64Decode

Decode a Base64-encoded string or single-byte integer vector.

Syntax out←{cpo} HttpCommand.Base64Decode b64
b64 Either a single-byte integer or character vector to be decoded
cpo (optional) If set to 0 or not supplied, Base64Decode will perform UTF-8 conversion on the result. If set to 1, no conversion will be performed. In almost all cases, you can ignore (and not supply) this argument.
out A character vector representing the decodes base-64 right argument.
Example(s)       HttpCommand.Base64Decode 'RHlhbG9nIOKNuuKNtOKMig=='
Dyalog ⍺⍴⌊

Base64Encode

Base64 encode a string or integer vector.

Syntax b64←{cpo} HttpCommand.Base64Encode in
in Either an integer or character vector to be encoded
cpo (optional) If set to 0 or not supplied, Base64Encode will first perform UTF-8 conversion on a character argument. If set to 1, no conversion will be performed. In almost all cases, you can ignore (and not supply) this argument.
b64 A character vector representing the base-64 encoding of the right argument.
Example(s)       HttpCommand.Base64Decode 'RHlhbG9nIOKNuuKNtOKMig=='
Dyalog ⍺⍴⌊

URL Encoding

URLs can only be sent over the Internet using the ASCII character set. However, URLs often contain characters outside the ASCII character set. URL encoding converts strings to a format acceptable for transmission over the Internet. URLEncoding is also used to encode payloads for content-type 'application/x-www-form-urlencoded'.

UrlDecode

URLDecode a URLEncoded string.

Syntax out←HttpCommand.UrlDecode in
in A URLEncoded string
out The URLDecoding of in.
Example(s)       HttpCommand.UrlDecode 'Dyalog%20%E2%8D%BA%E2%8D%B4%E2%8C%8A'
Dyalog ⍺⍴⌊

      HttpCommand.UrlDecode 'name=Donald%20Duck'
name=Donald Duck

      HttpCommand.UrlDecode 'first=Donald&last=O%27Mallard'
first=Donald&last=O'Mallard

UrlEncode

URLEncode a string or a set of name/value pairs.

Syntax out←{name} HttpCommand.UrlEncode in
in One of:
name (optional) The name for the URLEncoded right argument. Applies only in the case where in is a simple character vector.
out The URLEncoding of in.
Example(s)       HttpCommand.UrlEncode 'Dyalog ⍺⍴⌊'
Dyalog%20%E2%8D%BA%E2%8D%B4%E2%8C%8A

      'name' HttpCommand.UrlEncode 'Donald Duck'
name=Donald%20Duck

      HttpCommand.UrlEncode ('first' 'Donald') ('last' 'O''Mallard')
first=Donald&last=O%27Mallard