zoukankan      html  css  js  c++  java
  • smple

    //遍历文件
            static List<string> TraversalFile(string filePath,string fileExtension)
            {
                List<string> returnList = new List<string>();
                if (Directory.Exists(filePath) == true)
                {
                    DirectoryInfo theFolder = new DirectoryInfo(filePath);
                    var fileItem = from file in theFolder.GetFiles() where file.Extension == fileExtension select file;
                    foreach (var item in fileItem)
                        returnList.Add(item.Name.Replace(item.Extension, string.Empty));
                }
                return returnList;
            }

    //读XML
            static internal void Read()
            {
                var path = @"d:\Environment.xml";
                IDictionary<string, string> aa = new Dictionary<string,string>();
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(path);
                    var nodeList = doc.SelectSingleNode("config").ChildNodes;
                    foreach (XmlNode node in nodeList)
                    {
                        aa.Add(node.Name, node.InnerText);
                    }
                }
                catch
                {
                }
            }

        /// <summary>
            /// 匹配
            /// </summary>
            /// <param name="targetString"></param>
            /// <returns></returns>
            private int regexForInt(string targetString)
            {
                int result = 0;

                if (String.IsNullOrEmpty(targetString))
                {
                    return result;
                }
                else {
                    Regex intRule = new Regex(@"[0-9]+$");//只匹配结尾的数字,其他部分的数字会被忽略
                    if (intRule.Match(targetString, 0).Value!=string.Empty)
                        result = int.Parse(intRule.Match(targetString, 0).Value);
                    else
                    {
                        result = 0;
                    }

                   
                    //方法2:所有的数字都被选出来按照左至右顺序排列
                    //Regex intRule = new Regex(@"\d+");
                    //string tmp = "";
                    //foreach (Match loopRecord in Regex.Matches(targetString, @"\d+"))
                    //{
                    //    tmp += loopRecord.Value.ToString();
                    //}
                    //result = Convert.ToInt32(tmp);
                    return result;
                }

            }

  • 相关阅读:
    【C/C++开发】c++ 工具库 (zz)
    【机器学习】半监督学习
    【Python开发】Pycharm下的Anaconda配置
    【C/C++开发】emplace_back() 和 push_back 的区别
    【C/C++开发】容器set和multiset,C++11对vector成员函数的扩展(cbegin()、cend()、crbegin()、crend()、emplace()、data())
    【C/C++开发】C++11 并发指南三(std::mutex 详解)
    【C/C++开发】C++11 并发指南二(std::thread 详解)
    【C/C++开发】C++11 并发指南一(C++11 多线程初探)
    【C/C++开发】STL内嵌数据类型: value_type
    个股实时监控之综述
  • 原文地址:https://www.cnblogs.com/renfeng/p/2506352.html
Copyright © 2011-2022 走看看