C# ini 文件解析库
来源:互联网 发布:win10控制软件安装 编辑:程序博客网 时间:2024/05/16 14:07
ini解析
因为需要使用C#进行ini 文件读写操作, 看到官方说解析ini文件需要使用xml读写库。感觉太过麻烦。因为先前有MFC 读写INI文件的经验,感觉API非常简单,所以稍微封装了一下。
代码
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Runtime.InteropServices;namespace IniFile{ class IniParser { [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string default_var, StringBuilder retVal, int buff_size, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileInt(string section, string key, int default_var, string filePath); private string _file_path; public IniParser() { _file_path = Directory.GetCurrentDirectory()+"\\" +System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".ini"; } public IniParser(string t_filename) { if (string.IsNullOrEmpty(t_filename)) { _file_path = System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".ini"; return; } else { _file_path = t_filename; } } public bool writeData(string t_section, string t_key, string t_data) /// if write data sucess , return true ,otherwise return false { long i_result = WritePrivateProfileString(t_section, t_key, t_data, _file_path); return (i_result!=0?true:false); } public string readStringData(string t_section, string t_key, string t_default = "" ) /// if success , value would return , otherwise empty string return { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(t_section, t_key, t_default, temp, 255, this._file_path); return temp.ToString(); } public int readIntData(string t_section, string t_key, int t_default =0) { int i_result = GetPrivateProfileInt(t_section, t_key, t_default, this._file_path); return i_result; } }}
0 0
- C# ini 文件解析库
- ini文件解析c库(iniparser)
- ini文件解析c库(iniparser)
- python 解析ini 文件
- ini文件解析器
- php解析.ini文件
- INI文件解析类
- shell解析ini文件
- python解析ini文件
- shell解析ini文件
- ini文件解析器
- Java解析INI文件
- node解析ini文件
- Go-ini文件解析
- Python解析INI文件
- INI文件解析、遍历
- C#读写INI文件
- C#读写INI文件
- 网络游戏TCP长连接基本设计
- 《Java课程实习》日志(周一)
- Android百分比布局源代码解析
- AppStore被Rejected 的各种原因
- Android之Handler
- C# ini 文件解析库
- 用正则表达式验证邮箱和手机号
- 今天使用到的git语法
- index() 与 rindex() 的区别
- 《转》OpenStack Live Migration
- 在 Windows 上安装Rabbit MQ
- EazyUI TreeGrid分页、查询
- SQL_OPEN XML
- JQuery实现回车代替Tab键