XoDefender
XoDefender

Reputation: 33

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

Upvotes: 1

Views: 1299

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118310

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.

Upvotes: 1

Related Questions