標記爲C#這個問題? :-)
可能這樣嗎?全外使用LINQ加入:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
static IEnumerable<string[]> ReadTabFile(string fileName, char delimiter)
{
return File.ReadLines(fileName).Select(line => line.Split(delimiter));
}
static void Main()
{
string[][] lines1 = ReadTabFile("text1.txt", '|').ToArray();
string[][] lines2 = ReadTabFile("text2.txt", '|').ToArray();
var leftOuterJoin = from line1 in lines1
join line2 in lines2
on line1.FirstOrDefault() equals line2.FirstOrDefault()
select new
{
line1,
line2
};
var rightOuterJoin = from line2 in lines2
join line1 in lines1
on line2.FirstOrDefault() equals line1.FirstOrDefault()
select new
{
line1,
line2
};
var fullOuterJoin = leftOuterJoin.Union(rightOuterJoin);
foreach (var test in fullOuterJoin)
{
Console.WriteLine("{0,-40} - {1,-40}", string.Join("|", test.line1), string.Join("|", test.line2));
}
}
結果:
Bacon|Delicious|salty|lowcalorie - Bacon|pork|cheap|crispy
Sausage|Delicious|salty|highfat - Sausage|pork|cheap|null
Chicken|Chicken|chicken|highprotein - Chicken|Chicken|moderate|sandwiches
開始與[如何讀取CSV文件導入一個.NET數據表(http://stackoverflow.com/q/1050112/ 205233)(以及相關主題)...一旦將數據加載到DataTable中,它應該使您能夠使用所需的查詢。 – Filburt
...或給Oledb一個像[從CSV文件填充數據集](http://stackoverflow.com/a/16606837/205233)。 – Filburt