使用iconv()的UTF-8到C / POSIX语言环境转换失败

时间:2021-06-06 08:43:10

I am trying to convert UTF-8 string to C/POSIX locale string
The UTF-8 string is "abc123£" (in bash "abc123\302\243"`)

我试图将UTF-8字符串转换为C / POSIX语言环境字符串UTF-8字符串是“abc123£”(在bash“abc123 \ 302 \ 243”中)

  1. iconv_open("", "UTF-8"); // "" means default program locale i.e. C
  2. iconv_open(“”,“UTF-8”); //“”表示默认程序区域设置,即C.

  3. iconv_open("UCS-2LE", "UTF-8");

iconv() is returning EILSEQ to me in case 1, but success in case 2.

iconv()在案例1中将EILSEQ返回给我,但在案例2中成功。

What is the reason for this?
Also, how can I successfully convert any UTF-8 string to 'C' locale string.

这是什么原因?另外,如何将任何UTF-8字符串成功转换为“C”语言环境字符串。

1 个解决方案

#1


1  

Because your C locale uses a character set (probably US-ASCII) that doesn't have a character for £, and the string can't be converted without loss.

因为您的C语言环境使用的字符集(可能是US-ASCII)没有£的字符,并且无法在不丢失的情况下转换字符串。

#1


1  

Because your C locale uses a character set (probably US-ASCII) that doesn't have a character for £, and the string can't be converted without loss.

因为您的C语言环境使用的字符集(可能是US-ASCII)没有£的字符,并且无法在不丢失的情况下转换字符串。