zoukankan      html  css  js  c++  java
  • ini操作类

    public class IniHelper
    {
        // 声明INI文件的写操作函数 WritePrivateProfileString()
        [System.Runtime.InteropServices.DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        // 声明INI文件的读操作函数 GetPrivateProfileString()
        [System.Runtime.InteropServices.DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);

        private readonly int _retLength = 500;
        private readonly string _sPath = null;
        /// <summary>
        /// 初始化IniHelper
        /// </summary>
        /// <param name="path">ini文件保存路径</param>
        /// <param name="rl">默认500</param>
        public IniHelper(string path, int? rl = null)
        {
            this._sPath = path;
            this._retLength = rl.HasValue ? rl.Value : _retLength;
        }
        /// <summary>
        /// 设置Ini配置,默认配置节为Setting
        /// </summary>
        /// <param name="key">键名</param>
        /// <param name="value">键值</param>
        /// <param name="section">配置节</param>
        public void WriteValue(string key, string value, string section = "Setting")
        {
            // section=配置节,key=键名,value=键值,path=路径
            WritePrivateProfileString(section, key, value, _sPath);
        }
        /// <summary>
        /// 根据键名节点读取Ini配置,默认节点为Setting
        /// </summary>
        /// <param name="key">键名</param>
        /// <param name="section">配置节</param>
        /// <returns></returns>
        public string ReadValue(string key, string section = "Setting")
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(_retLength);
            // section=配置节,key=键名,temp=上面,path=路径
            GetPrivateProfileString(section, key, "", temp, _retLength, _sPath);
            return temp.ToString();
        }
    }

     

    2017-07-10 09:42:56

  • 相关阅读:
    CSP-S2019 括号树
    [CQOI2007]余数求和
    CF1000E We Need More Bosses
    [HAOI2009]毛毛虫
    ls命令
    HTML的标签 属性 等等
    虚拟机安装Tools
    1.1 什么是安全渗透
    004-Kali Linux安装-熟悉环境
    003-Kali Linux 安装-持久加密USB安装、熟悉环境、熟悉BASH命令
  • 原文地址:https://www.cnblogs.com/D-LuFei/p/7144362.html
Copyright © 2011-2022 走看看