How to read and write special characters in the INI configuration file?

How to read and write special characters in the INI configuration file?


//Read function as follows, read no special characters, read the content is empty
[DllImport("kernel32")]
public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public static string strGetIniKeyValue(string section, string key, string def, string filePath)
        {
            StringBuilder sbTmp = new StringBuilder(20);
            
            GetPrivateProfileString(section, key, def, sbTmp, 20, filePath);
            return System.Convert.ToString(sbTmp);
        }

//The write function can be written as follows, special character, but when writing not covered by the original content, just before the new content into the original content
[DllImport("kernel32")]
public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

Started by Abby at November 27, 2016 - 3:04 AM

You can code, such as Base64 code

Posted by Yolanda at December 05, 2016 - 3:10 AM

Ask specifically how to code.

Posted by Abby at December 19, 2016 - 3:20 AM

Let me guess what is the special character, never guess

Posted by Saxon at December 22, 2016 - 3:49 AM

base64
Code:
byte[] bytes=Encoding.Default.GetBytes("Want to convert the string");
 Convert.ToBase64String(bytes);

Decode:
//"ztKwrsTj""Base64 code I love you"
byte[] outputb = Convert.FromBase64String("ztKwrsTj");
string orgStr= Encoding.Default.GetString(outputb);

Posted by Abby at December 27, 2016 - 4:26 AM