5.4.1 字符串编码

 
native_bytes = unicode2native (utf8_str, codepage)
native_bytes = unicode2native (utf8_str)

使用代码页 codepage 将 UTF-8 字符串 utf8_str 转换为字节流。

字符向量 utf8_str 被转换为字节流 native_bytes,使用参数 codepage 指定的代码页。字符串 codepage 必须是有效代码页的标识符。有效代码页的示例包括 "ISO-8859-1""Shift-JIS""UTF-16"。有关支持的代码页列表,请参见 https://www.gnu.org/software/libiconv。如果省略或为空 codepage,则使用系统默认代码页。

如果任何字符无法映射到代码页 codepage,它们将被替换为该代码页的适当替换序列。

另请参阅: native2unicode

 
utf8_str = native2unicode (native_bytes, codepage)
utf8_str = native2unicode (native_bytes)

使用代码页 codepage 将字节流 native_bytes 转换为 UTF-8。

向量 native_bytes 中的数字被四舍五入并裁剪为 0 到 255 之间的整数。然后,该字节流被映射到字符串 codepage 所指定的代码页,并以字符串 utf8_str 的形式返回。Octave 使用 UTF-8 作为其内部编码。字符串 codepage 必须是有效代码页的标识符。有效代码页的示例包括 "ISO-8859-1""Shift-JIS""UTF-16"。有关支持的代码页列表,请参见 https://www.gnu.org/software/libiconv。如果省略或为空 codepage,则使用系统默认代码页。

如果 native_bytes 是字符串向量,则按原样返回。

另请参阅: unicode2native


版权所有 © 2024-2026 Octave中文网

ICP备案/许可证号:黑ICP备2024030411号-2