zoukankan
html css js c++ java
ini文件的读取
写了个读取
形如
[
Database Info
]
GroupNum
=
3
CharSet
=
3383
[
drivers
]
wave
=
mmdrv.dll
timer
=
timer.drv
ini配置文件读取的方法如下:
Hashtable ReadingINI(
string
fileName)
{
Hashtable htSection
=
new
Hashtable();
Hashtable htKey
=
new
Hashtable();
System.Text.Encoding encode
=
System.Text.Encoding.GetEncoding(
"
GB2312
"
);
string
fileDataLine
=
null
;
Match match;
Regex regSection
=
new
Regex(
@"
^\[(?<key>.+)\]$
"
);
Regex keySection
=
new
Regex(
@"
^(?<key>.+)=(?<value>.+)$
"
);
StreamReader streamReader
=
new
StreamReader(fileName, encode);
fileDataLine
=
streamReader.ReadLine();
while
(fileDataLine
!=
null
)
{
if
(
!
(fileDataLine.StartsWith(
"
#
"
)
||
fileDataLine.StartsWith(
"
;
"
) ))
{
match
=
keySection.Match(fileDataLine);
if
(match.Success)
{
htKey.Add(match.Result(
"
${key}
"
), match.Result(
"
${value}
"
));
}
else
{
match
=
regSection.Match(fileDataLine);
if
(match.Success)
{
htKey
=
new
Hashtable();
htSection.Add(match.Result(
"
${key}
"
), htKey);
}
}
}
fileDataLine
=
streamReader.ReadLine();
}
streamReader.Close();
streamReader
=
null
;
return
htSection;
}
假设用上面的代码读上上面的配置文件, 返回值名字是 htINI
则可用如下方法取出timer对应的值
Hashtable htSection
=
htINI[
"
drivers
"
]
as
Hashtable;
if
(
null
!=
htSection)
{
return
htSection[
"
timer
"
];
}
else
{
return
string
.Empty;
}
查看全文
相关阅读:
JS的运行机制
Vue路由
javascript的逼格
Vue开发中遇到的问题及解决方案
模块模式
2019年终总结
http知识总结
小议函数的节流和防抖
nodejs初探一二
Object是个什么鬼
原文地址:https://www.cnblogs.com/sun_moon_earth/p/592339.html
最新文章
stone [期望]
POI2015 WYC
带权物品背包问题
树状数组[区间修改,区间查询]
或与异或 [背包DP]
卡特兰(Catalan)数入门详解
异或序列 [set优化DP]
Linux新装系统简单指南
vuex的mutations与actions的使用测试
['1','2','3'].map(parseInt)
热门文章
解决Element-u的 el-form 使用 v-if校验失灵问题
tab切换引起浏览器卡顿
web与后台交互--websocket
puppeteer 学习
Internal Server Error
解析RSS数据
远程办公两三事
MongoDB安装过程中出现service MongoDB failed to start,verify that you have sufficient privileges to start...
函数学习笔记
canvas绘制直线
Copyright © 2011-2022 走看看