# Method string_to_utf8()

Method string_to_utf8

  ``string(8bit)` string_to_utf8(`string` `s`)`
  ``string(8bit)` string_to_utf8(`string` `s`, `int` `extended`)`

Description

  Converts a string into an UTF-8 compliant byte-stream.

Note

  Throws an error if characters not valid in an UTF-8 stream are encountered. Valid characters are in the ranges `0x00000000-0x0000d7ff` and `0x0000e000-0x0010ffff`.

  If `extended` is 1 then characters outside the valid ranges are accepted too and encoded using the same algorithm. Such encoded characters are however not UTF-8 compliant.

See also

  Charset.encoder(), string_to_unicode(), unicode_to_string(), utf8_to_string()