C#读写INI配置文件

来源:互联网 发布:matlab 矩阵正交化 编辑:程序博客网 时间:2024/05/17 09:17

 

引进

using System.Collections.Specialized;


        //Define API function for write and read the INI file
        [DllImport("kernel32")]

       //此为写入

         private static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
       //此为读出

        //GetPrivateProfileString("节名","Name","没有获得匹配",s,len(s),你那ini的路径);
        private static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);

      请注意读出来的是一个int型的数。所以需要换转,下面给出程序转换片断例子:

    

      int length = GetPrivateProfileString("分類", arrCode[i], "", byBuffer, byBuffer.GetUpperBound(0), filePath);
                    if (length != 0)
                    {

                        string str = Encoding.GetEncoding(0).GetString(byBuffer);
                        //string[] strSplit = str.Split('|');
                     }

原创粉丝点击