简体   繁体   中英

How to convert Windows-1251(ISO-88-59-5) string to UTF-8 string on Linux?

I have a common string, which is encoded like ISO-88-59-5 and I want to transform this string to UTF-8 format, by the way, I have the code example on C# which is working well. I need to do the same on C++

result = mainString.Substring(nameStart + 3, symbols);
Encoding enc = Encoding.GetEncoding("ISO-8859-5");
byte[] bytes = enc.GetBytes(result);
                
result = Encoding.UTF8.GetString(bytes);

result is a string with text

The procedure to do this on Linux is as follows:

  1. Use iconv_open() as described in its manual page to create a handle for a conversion from windows-1251 to UTF-8. I just double-checked and "windows-1251" is supported by the iconv library.

  2. Use iconv() as described in its manual page .

  3. Use iconv_close() as described in its manual page .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM