zoukankan      html  css  js  c++  java
  • 读取ini文件返回Dictionary<>的ini文件读取器

    Dictionary<string, Dictionary<string, string>> readIni(string filePath)

            {

                int count = 0;//计算节点数

                int j = 0;//节点数值下标

                string[] lines = System.IO.File.ReadAllLines(filePath, Encoding.Default);

                foreach (string item in lines)

                {

                    Console.WriteLine(item);

                    if (item.StartsWith("[") && item.EndsWith("]"))

                    {

                        count++;

                    }

                }

                string[] nodeName = new string[count];

                #region 确定节点数组

                for (int i = 0; i < lines.Length; i++)

                {

                    if (lines[i].StartsWith("[") && lines[i].EndsWith("]"))

                    {

                        while (j < count)

                        {

                            nodeName[j] = lines[i];

                            j++;

                            break;

                        }

                    }

                }

                #endregion

                Dictionary<string, string>[] dicKey=new Dictionary<string, string>[count];

                Dictionary<string, Dictionary<string, string>> dic = new Dictionary<string, Dictionary<string, string>>();

                for (int m = 0; m < lines.Length; m++)

                {

                    for (int i = 0; i < count; i++)

                    {

                        if (lines[m].Contains(nodeName[i]))//某个节点所在的行

                        {

                            for (int n = m + 1; n < lines.Length; n++)

                            {

                                //读到下一个节点跳出

                                if ((i + 1) < count && lines[n].Contains(nodeName[i + 1]))//位置不能颠倒

                                {

                                    break;

                                }

                                string str1 = lines[n].Substring(0, lines[n].IndexOf("="));

                                string str2 = lines[n].Substring(lines[n].IndexOf("=") + 1);

                                dicKey[i][str1] = str2;                           

                            }

                            dic.Add(nodeName[i], dicKey[i]);

                        }

                    }

                }

                return dic;

            }

  • 相关阅读:
    超链接把一个值传到多个页面的方法
    jsp采用数据库连接池的方法获取数据库时间戳context.xml配置,jsp页面把时间格式化成自己需要的格式
    Myeclipse WEB工程JSP使用JNDI 数据库连接池连接Mysql数据库
    jsp页面图片显示不出来
    如何修改MyEclipse的默认编码方式
    MyEclipse8.5破解方法
    mysql创建的数据库在电脑什么位置?
    netsh winsock reset
    SQL Server(MSSQLSERVER)启动失败,提示“请求失败或服务未及时响应
    WIN7不能上网
  • 原文地址:https://www.cnblogs.com/yichengbo/p/2134286.html
Copyright © 2011-2022 走看看