c# - 在 2 个数组 c# 中查找匹配值
问题描述
所以我试图在文件名和 SQL 数据集之间进行匹配。
例如 Recordset 包含一个 1000,1001,1002,1003 的数组
我的文件列表包含一个数组 "c:\temp\100.txt","c:\temp\1000.txt","c:\temp\1001.txt","c:\temp\2002.txt" ,"c:\temp\100.txt","c:\temp\1000-1.txt"
所以我的目标是得到以下结果:
c:\temp\1000.txt c:\temp\1001.txt c:\temp\1000-1.txt
我如何做到这一点?
我试过这样的东西
private static String[] GetImageList()
{
return Directory.GetFiles("C:\\tempbilledeimport\\", "*.*", SearchOption.AllDirectories);
}
private static List<string> SQLRecordset()
{
List<string> items = new List<string>();
string queryString = "select item from inventory where WebUseOnWeb=1";
using (SqlConnection connection = new SqlConnection(DatabaseConnection.SqlConnectionStringCompany))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
// Call Read before accessing data.
items.Add(reader[0].ToString());
reader.Close();
}
return items;
}
但是我如何比较它们呢?
解决方案
创建一个包含文件名的整数 HashSet,您可以从其中将 c:\temp\ 和 .txt 替换为空字符串,然后将它们转换为整数。
您现在可以检查您获得的每个整数是否在 HashSet 中都有匹配项。
我可以看到你有一个 1000-1.txt 文件。不知道你想如何处理。是比赛吗?
推荐阅读
- matlab - 在matlab中抛出错误后返回语句
- python - 如果我执行以下代码,我会收到类型错误,错误是 TypeError: 'float' object cannot be mapped as an integer
- html - Mat-Table 区域中的 CSS 问题
- flutter - Flutter 总是需要热重载
- php - .htaccess 和第二个和更多参数的问题
- scala - 在 Scala 中按名称传递
- angular - 包含自定义组件 html 的角度管道
- linux - 从文本文件中查找内容与某行匹配的文件
- javascript - 用钩子反应功能组件 - 从用 reducer 编写的函数中获取响应
- sql - 是否有一个 SQL 函数可以在 Date 列中填充缺失的日期并用以前的值填充 B 列中的相同记录?(PostgresSQL)