zoukankan      html  css  js  c++  java
  • 高效判断txt中数据行是否重复

    说明:具体时间没测,但是是试过的几种方式中最快的一种。

         bool test(string findkey)
            {
                string path = "/ResidentFlash/custinfo/custinfo.txt";
                FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("gb2312"));
                reader.BaseStream.Seek(0L, SeekOrigin.Begin);
                bool flag=false;
                while (reader.Peek() >= 0)
                {
                    try
                    {
                        string str = reader.ReadLine().Trim();
                        string txtkey = str.Substring(0, 4);
                        if ((str == null) || (str.Length <= 0))
                        {
                            break;
                        }
    
                        if (txtkey.Trim() == findkey.Trim())
                        {
                            reader.Close();
                            stream.Close();
                            flag = true;//找到
                  return flag;
    } } catch (Exception) { } } if (flag == false)
            {
              MessageBox.Show("不存在");
            } reader.Close(); stream.Close();
    return flag; }
  • 相关阅读:
    C++赌博游戏
    数据挖掘--数据准备
    非线性维归约Isomap
    ClampedCubicSpline
    Romberg算法
    列表与数组
    HttpClient调用webApi时注意的小问题
    Week4
    Week3
    Week2
  • 原文地址:https://www.cnblogs.com/lilixiang-go/p/5041350.html
Copyright © 2011-2022 走看看