#region 获取相同数据数量
/// <summary>
/// 相同数据数量统计
/// </summary>
/// <param name="inList">输入列表</param>
/// <returns></returns>
public List<string> GetSameNumber(List<string> inList)
{
List<string> OList = new List<string>();//输出列表
List<double> saveTXT = new List<double>();
int allcount = inList.Count;
int aa = 0;
foreach (string i in inList)
{
aa += 1;
Console.WriteLine(aa + "" + "/" + allcount + "");
for (int j = 0; j < i.Split(',').Length - 1; j++)
{
saveTXT.Add(Convert.ToDouble(i.Split(',')[j]));
}
}
// result集合存放扫描结果
Dictionary<double, RepeatInfo> result = new Dictionary<double, RepeatInfo>();
// 遍历整型列表集合,查找其中的重复项
foreach (double v in saveTXT)
{
if (result.ContainsKey(v))
{
result[v].RepeatNum += 1;
}
else
{
RepeatInfo item = new RepeatInfo() { Value = v, RepeatNum = 1 };
result.Add(v, item);
}
}
foreach (RepeatInfo info in result.Values)
{
if (info.RepeatNum > 1)
{
OList.Add(info.Value + "" + "," + info.RepeatNum + "");
}
}
return OList;
}
/// <summary>
/// 获取相同数据数量(手写版(贼慢))
/// </summary>
/// <param name="SaveAll">List格式存储的字符串</param>
public List<String> GetNumber(List<String> SaveAll)
{
//存储不同类型的数据
List<String> SaveString = De_Weight(SaveAll);
//计数
int nub = 0;
//存储最终数据及数量
List<String> SaveString1 = new List<string>();
foreach (string i in SaveString)
{
foreach (string n in SaveAll)
{
for (int j = 0; j < n.Split(',').Length; j++)
{
if (i == n.Split(',')[j])
{
nub += 1;
}
}
}
SaveString1.Add(i + "," + nub + "");
nub = 0;
}
return SaveString1;
}
#endregion
C# TXT相同数据数量统计
最新推荐文章于 2024-04-30 22:56:29 发布