I am trying to read foreign characters from a .ini file. This is the method I use.
[DllImport("kernel32")] public static extern int GetPrivateProfileString(string Section, int Key, string Value, [MarshalAs(UnmanagedType.LPArray)] byte[] Result, int Size, string FileName); public static string[] GetEntryNames(string section, string iniPath) { for (int maxsize = 500; true; maxsize *= 2) { byte[] bytes = new byte[maxsize]; int size = Imports.GetPrivateProfileString(section, 0, "", bytes, maxsize, iniPath); if (size < maxsize - 2) { string entries = Encoding.ASCII.GetString(bytes, 0, size - (size > 0 ? 1 : 0)); Console.WriteLine("Entries: " + entries.Split(new char[] { '\0' })[3]); return entries.Split(new char[] { '\0' }); } } }
I am using Encoding.ASCII , but obviously GetPrivateProfileString not. Bytes coming out of it need encoding. How can i do this?
Edit: Example
It will print: Tavar? instead of tavaré
c # file char encoding byte
John P.
source share