• 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;
    }
  • 相关阅读:
    Linux如何修改命令提示符
    Linux命令详解-install
    Linux命令详解-info
    Linux命令详解-man
    Linux命令详解-printf
    Linux命令详解-echo
    Linux命令详解-whatis
    Linux命令详解-file
    Linux命令详解-help
    Linux命令详解-type
  • 原文地址:https://www.cnblogs.com/sun_moon_earth/p/592339.html
Copyright © 2020-2023  润新知