U
U
up72018-05-30 11:25:52
Character encoding
up7, 2018-05-30 11:25:52

How to read from ini to UTF-8 in C#?

Reading method:

[DllImport("kernel32", CharSet = CharSet.Unicode)] 
static extern int GetPrivateProfileStringW(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);

  public string ReadINI(string Section, string Key)
        {
            var RetVal = new StringBuilder(255);
            GetPrivateProfileStringW(Section, Key, "", RetVal, 255, Path);
            return RetVal.ToString();
        }

I read this: And anyway, the result is a str variable in the cp1251 format. I can, of course, convert it to UTF-8 from cp1251, but how to do it with Chinese ones?
String str = INI.ReadINI("Settings", "Lan");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2018-05-30
@devspec

Why WinAPI? There are also https://github.com/rickyah/ini-parser and others

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question