• 操作ini文件帮助类


    public class AccessIni
        {
            /// <summary>
            /// 写入INI文件
            /// </summary>
            /// <param name="section"></param>
            /// <param name="key"></param>
            /// <param name="value"></param>
            /// <param name="filePath">路径</param>
            /// <returns></returns>
            [DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section, string key, string value, string filePath);
    
            /// <summary>
            /// 读取INI文件
            /// </summary>
            /// <param name="section"></param>
            /// <param name="key"></param>
            /// <param name="defValue">未读到的默认值</param>
            /// <param name="retValue">读到的默认值</param>
            /// <param name="size">大小</param>
            /// <param name="filePath">路径</param>
            /// <returns></returns>
            [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string defValue, StringBuilder retValue, int size, string filePath);
    
    
            /// <summary>
            /// 读取ini文件
            /// </summary>
            /// <param name="section"></param>
            /// <param name="key"></param>
            /// <param name="defValue">未读取到值时的默认值</param>
            /// <param name="filepath">文件路径</param>
            /// <returns></returns>
            public string ReadIni(string section, string key, string defValue, string filepath)
            {
                string strValue = "";
                StringBuilder retValue = new StringBuilder();
                GetPrivateProfileString(section, key, defValue, retValue, 256, filepath);
                strValue = retValue.ToString();
                return strValue;
            }
    
            /// <summary>
            /// 写入ini文件
            /// </summary>
            /// <param name="section"></param>
            /// <param name="key"></param>
            /// <param name="value"></param>
            /// <param name="filePath">文件路径</param>
            /// <returns></returns>
            /// 
            public long WriteIni(string section, string key, string value, string filePath)
            {
                return WritePrivateProfileString(section, key, value, filePath);
            }
    
            /// <summary>
            /// 删除节
            /// </summary>
            /// <param name="section"></param>
            /// <param name="filePath">文件路径</param>
            /// <returns></returns>
            public long DeleteSection(string section, string filePath)
            {
                return WritePrivateProfileString(section, null, null, filePath);
            }
    
            /// <summary>
            /// 删除键
            /// </summary>
            /// <param name="section"></param>
            /// <param name="key"></param>
            /// <param name="filePath">文件路径</param>
            /// <returns></returns>
            public long DeleteKey(string section, string key, string filePath)
            {
                return WritePrivateProfileString(section, key, null, filePath);
            }
        }
  • 相关阅读:
    __slots__魔法,减少实例属性消耗的内存
    在函数中最好不要用可变类型当参数
    Python的容器模块
    实例和类变量以及类的魔术方法
    推导式
    Python内置函数
    常用的git操作(持续更新)
    h开头的
    e开头的
    如何迁移测试的MAGENTO到正式运行的MAGENTO
  • 原文地址:https://www.cnblogs.com/liuslayer/p/10726835.html
Copyright © 2020-2023  润新知