文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>快速从多个txt文本里面查找重复号码

快速从多个txt文本里面查找重复号码

时间:2011-05-05  来源:曾祥展

批量快速查找重复号码小程序 界面如下:

 

txt文本里面数据格式:一个号码一行

重点代码:

/// <summary>
/// 从文本文件中返回重复的字符串行
/// </summary>
/// <param name="Path"></param>
/// <returns></returns>
public string GetRepeatStrFromArrayList(string Path)
{
    Dictionary<string, int> array = GetArrayListFromTxt(Path);
    ArrayList list = new ArrayList();
    string buildstr = "";
    int i = 0;
    foreach (var item in array)
    {
        this.progressBar1.Maximum = array.Count;
        this.progressBar1.Value = i;

        i++;

        if (item.Value > 1)
        {
            buildstr += item.Value + "个   " + item.Key + "\r\n";
        }

    }

    if (buildstr == "")
    {
        buildstr = "查找完毕!没有重复!";
    }
    else
    {
        buildstr += "\r\n"+"以上是重复的!";
        buildstr += "总共:" + array.Count+"个不重复!  ";
        buildstr += "查找完毕!";
    }

    return buildstr;
}


/// <summary>
/// 将文本文件中数据读取出来并放到Dictionary中返回
/// </summary>
/// <param name="Path"></param>
/// <returns></returns>
public static Dictionary<string, int> GetArrayListFromTxt(string Path)
{
    string strLine = "";
    Dictionary<string, int> dct = new Dictionary<string, int>();
    int i = 1;
    try
    {
        FileStream fs = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
        StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);

        while (strLine != null)
        {
            strLine = sr.ReadLine();
            if (dct.ContainsKey(strLine))//如果字典中已存在这个键,给这个键值加1
            {
                dct[strLine]++;
            }
            else
            {
                dct.Add(strLine, 1);//字典中不存在这个键,加入这个键
            }
            i++;
        }
        sr.Dispose();
        sr.Close();
        fs.Close();

    }
    catch (Exception ex)
    {
    }
    return dct;
}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载