C#如何操作ini文件(读写操作)……

猿猿相抱 2009-04-06 12:52:47
类似这种形式的ini文件
———————————————————————————————
[Loading]
background=UI\Loading\background.bmp
font=宋体

[run]
font=黑体
————————————————————————————————

如何用c#进行读取,改写的操作?

改变各项的值
...全文
875 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
niitnanfeng 2009-04-06
  • 打赏
  • 举报
回复
018 2009-04-06
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wuyq11 的回复:]
引入命名空间
using System.Runtime.InteropServices;
声明 [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 def, StringBuilder retVal, int size, string filePath);
进行…
[/Quote]

TY
kbtjh 2009-04-06
  • 打赏
  • 举报
回复
up
GavinKeng 2009-04-06
  • 打赏
  • 举报
回复
[DllImport("kernel32.dll")] //写INI
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32.dll")] //读INI
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

参数应该能看懂是什么意思吧。
wuyq11 2009-04-06
  • 打赏
  • 举报
回复
引入命名空间
using System.Runtime.InteropServices;
声明 [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 def, StringBuilder retVal, int size, string filePath);
进行操作
参考
coodd 2009-04-06
  • 打赏
  • 举报
回复
ini文件也是文本文件,直接用StreamReader和StreamWriter读写就行了。
mykelly6 2009-04-06
  • 打赏
  • 举报
回复
直接点就一行一行的读,读到没数据的就作为一小块数据的结束,然后这一块比如
[run]
font=黑体
用正则来分析阿

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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