As question How to match the 2 column of item by refering to another txt file in C#. For example, currently I'm doing the comparison by matching one of the column in both txt file. If the id of 1st txt file equals to 2nd file then perform my operation.
But the problem is both of the have the different id but refering to same things.
How do I take the value in the 1st txt file by searching with the another new created txt file which have the following reference data
reference_file:
1,AAA
2,BBB
3,CCC
Example of 1st txt file 1st column
info1,info2,info3,info1,2,info4,info5,info6,info7
Example of 2nd txt file 1st column
info1,info2,info3,info1,bbb,info4,info5,info6,info7
If the column in 1st txt file is 2 then the value is BBB
Currently one of the line will do this matching if both of the column id with same value.
static void Main(string[] args)
{
DataTable dt_1sttxtfile = ConvertToDataTable(@"C:\Users\manchunl\Desktop\1sttxtfile.txt", 10);
DataTable dt_2ndtxtfile = ConvertToDataTable(@"C:\Users\manchunl\Desktop\2ndtxtfile.txt", 10);
DirectoryInfo reference_file = new DirectoryInfo(@"C:\Users\manchunl\Desktop\Reference.txt");
foreach (DataRow row1 in dt_1sttxtfile.Rows)
{
foreach (DataRow row2 in dt_2ndtxtfile.Rows)
{
var 1sttxtfileRow = row1.ItemArray;
var 2ndtxtfileRow = row2.ItemArray;
if (1sttxtfileRow[4].Equals(2ndtxtfileRow[4]))
{
//Perform my task
}
}
}
}
Sorry for bad explanation if my explaination not clear.