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;
    ifnull != 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
Copyright © 2011-2022 走看看