• INI文件阅读器


     class Program
        {
            static void Main(string[] args)
            {
                int count = 0;//计算节点数
                int j = 0;//节点数值下标
                string[] lines = System.IO.File.ReadAllLines(@"d:xxx.ini", 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
                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);
                                string str3 = "(" + nodeName[i] + ",(" + str1 + "," + str2 + "))";
                                Console.WriteLine(str3);
                            }
                        }
                    }
                }
                Console.ReadKey();
            }
        }

  • 相关阅读:
    一种稀少的漏洞-内网穿透代理漏洞【原创】
    实战修改密码处的一处逻辑问题【原创】
    Redis Cluster集群搭建与配置
    tomcat热部署,更改java类不用重新加载context
    Redis集群方案应该怎么做
    Flume + HDFS + Hive日志收集系统
    hadoop 1.2 集群搭建与环境配置
    epub、ocf等常用电子书格式浅析----附JAVA示例程序
    zookeeper-3.4.8 集群搭建
    centos6.6 虚拟机集群搭建
  • 原文地址:https://www.cnblogs.com/yichengbo/p/2133873.html
Copyright © 2020-2023  润新知