file-codeEncoding

Bytes to string, string to bytes

chevron-rightSupported encodingshashtag
  1. UTF-8

  2. UTF-16

  3. UTF-16BE

  4. UTF-16LE

  5. UTF-32

  6. UTF-32BE

  7. UTF-32LE

  8. ASCII

  9. ISO-8859-1

  10. CP1251

  11. CP1252

  12. KOI8-R

  13. KOI8-U

  14. WINDOWS-1251

stringToBytes(text, encoding)

Parameters:

  • text (string).

  • encoding (encoding).

Return:

  • bytes, err

Example Usage:

local text = "Hello, ΠΌΠΈΡ€!"
local bytes, err = encoding.stringToBytes(text, "UTF-8")
if bytes then
    print("   ВСкст: " .. text)
    print("   Π‘Π°ΠΉΡ‚Ρ‹: ", table.concat({table.unpack(bytes)}, ", "))
else
    print("   Ошибка: " .. err)
end

bytesToString(bytes, encoding)

Parameters:

  • bytes (table).

  • encoding (encoding).

Return:

  • string, err

Example Usage:

Last updated