c# - 当他们的前 8 位数字匹配时如何获取行比较
问题描述
当只有前 8 位数字匹配时,我需要获取从 2 列进行比较的值
这是一些代码
string[] titles1 = a.Split(new[] { ';', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
string[] titles2 = b.Split(new[] { ';', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
var Result = titles1.Union(titles2).Except(titles2).ToArray();
For Example:
Column-1 Column-2
'89118432 20190602' '89115496 20190602'
'89114023 20180602' '89114023 20180602'
'89110101 20190602' '89118432 20170602'
It's value i need
'89118432 20190602'
解决方案
尝试这个,
string[] column1 = new[]
{
"89118432 20190602",
"89114023 20180602",
"89110101 20190602"
};
string[] column2 = new[]
{
"89115496 20190602",
"89114023 20180602",
"89118432 20170602"
};
// first by using union, making them as a single array
List<IGrouping<string, string>> dataList = column1.Union(column2)
.GroupBy(x => string.Join("", x.Take(8))).Where(x => x.Count() > 1).ToList();
// then by using Take extension, we took first 8 character. By Where extension we searched over array that 8 characters if exists more then 1.
希望有所帮助,
推荐阅读
- regex - 如何在perl中将字符串中的字母和数字分开?
- javascript - 我的 Jquery 代码有什么问题?如果密码不匹配,尝试不重新加载表单
- r - 遍历DataTable为每个ID建立一个模型
- java - 是否有从 Optional 到 Stream 的便捷映射方法?
- c# - 对于 HEX 益智游戏,对象彼此重叠生成
- firebase - Firebase 云函数返回错误 429
- api - 是否可以进行 API 调用以在 Google My Business API 中使用 [不发布] 各种参与餐厅的菜单?
- sql-server - 有没有办法在更新字段时更改列的其他字段?
- jquery - 从 Google 地图自定义标记的信息窗口中删除关闭标题属性
- javascript - rxjs 可观察管道内的建模和 if/else 模式