C#中读写INI文件的方法详解下载

weixin_39820780 2019-07-04 12:00:18
C#中读写INI文件的方法详解,详细源代码介绍
相关下载链接://download.csdn.net/download/zdr53227/2803151?utm_source=bbsseo
...全文
10 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
ini读写代码详解实例,有很详细注释,保证满意; 预览截取一部分代码: ///    /// 读取INI文件指定INI文件的所有节点名称(Section)   ///    /// iniFile">Ini文件   /// 所有节点,没有内容返回string[0]   public static string[] INIGetAllSectionNames(string iniFile) { uint MAX_BUFFER = 32767; //默认为32767   string[] sections = new string[0]; //返回值   //申请内存   IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char)); uint bytesReturned = GetPrivateProfileSectionNames(pReturnedString, MAX_BUFFER, iniFile); if (bytesReturned != 0) { //读取指定内存的内容   string local = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned).ToString(); //每个节点之间用\0分隔,末尾有一个\0   sections = local.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } //释放内存   Marshal.FreeCoTaskMem(pReturnedString); return sections; } ///    /// 获取INI文件指定节点(Section)的所有条目(key=value形式)   ///    /// iniFile">Ini文件   /// 节点名称   /// 指定节点的所有项目,没有内容返回string[0]   public static string[] INIGetAllItems(string iniFile, string section) { //返回值形式为 key=value,例如 Color=Red   uint MAX_BUFFER = 32767; //默认为32767   string[] items = new string[0]; //返回值   //分配内存   IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER * sizeof(char)); uint bytesReturned = GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, iniFile); if (!(bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0)) { string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned); items = returnedString.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); } Marshal.FreeCoTaskMem(pReturnedString); //释放内存   return items; }

12,795

社区成员

发帖
与我相关
我的任务
社区描述
CSDN 下载资源悬赏专区
其他 技术论坛(原bbs)
社区管理员
  • 下载资源悬赏专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧