我只知道按照key值一个一个来读,但是我的Ini文件内容比较多,想依次全部读取,应该怎么办?
解决方案 »
- 求winform中可编辑行,在最后一行新增记录的datagridview的源码
- 如何取得数据表中的字段名?
- 关于提示窗口的问题,在C#中像CSDN上面结贴时那样提示窗口是怎么实现的?
- vs2005:DataGridView中使用DataGridViewComboBoxColumn问题
- C#在连接SQL2000时的问题 急!!
- 怎么才能自动输入登陆网站所需的用户名和密码?
- 怎样利用ADO.NET来连接Excel文件?
- 如何实现当传过来一个值和GridView的某一行主键值相等时候,该行颜色变化?
- 请教:关于注销session,返回登录界面的麻烦事
- 为什么平台选的x86,在xp上还是无效的win32程序……
- Cefsharp的中断点已到达的问题!急急急
- 微信卡卷有时候正常有时候刷新会报签名错误
自己做又不复杂,为什么非要在Win 3.1时代的GetPrivateProfileString树上吊死?
GetPrivateProfileString(null, null, "", buff, buff.Length, filePath);取全部section
GetPrivateProfileString(section, null, "", buff, buff.Length, filePath);取key
GetPrivateProfileString(section, key, "", buff, buff.Length, filePath);取value
不会递归就写几个循环,加一起也就十几二十行代码的事
qDebug()<<QString::fromLocal8Bit( str.toLatin1() );
setting.beginGroup( str );
for( int i = 0; i < setting.allKeys().size(); i++ )
{
QString str1 = setting.allKeys().at(i);
qDebug()<<i<<QString::fromLocal8Bit( str1.toLatin1() )
<<QString::fromLocal8Bit( setting.value( str1 ).toString().toLatin1() );
}
setting.endGroup();
}
亲测,可用
/// 获取配置文件中某个Key的值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetConfigValue(string key)
{
try
{
System.IO.FileInfo finfo = new System.IO.FileInfo(System.Reflection.Assembly.GetCallingAssembly().Location);
string path = finfo.DirectoryName + "\\config.ini";
if (!System.IO.File.Exists(path))
{
using (System.IO.File.Create(path))
{
}
}
using (System.IO.StreamReader sr = new System.IO.StreamReader(path))
{
while (!sr.EndOfStream)
{
string line = sr.ReadLine().Trim();
if (line.StartsWith(key))
{
return line.Replace(key + "=", "");
}
}
}
}
catch (Exception ex)
{ }
return "";
}