私は、ファイル内のいずれかの列からタイムスタンプでソートする必要がある2つのプレーンテキストファイルを持っています。 output_File.txt2つのテキストファイルをTimeStampでマージする
sample_A.txt
05:37:58 01:00 0 0 |05:32:00|93328|5352| |Description 1
05:43:58 01:00 0 0 |05:49:40|99256|5357| |Description 2
05:44:58 00:30 0 0 |05:50:40|99301|5358| |Description 3
sample_B.txt
04:58:11 00:02 0 0 |04:58:55|58787|0335| |Description A
04:58:12 01:01 0 0 |04:59:00|57701|0336| |Description B
06:09:37 01:00 0 0 |06:10:00|58181|0348| |Description C
(これはファイルをマージした後どのように見えるかである)
04:58:11 00:02 0 0 |04:58:55|58787|0335| |Description A
04:58:12 01:01 0 0 |04:59:00|57701|0336| |Description B
05:37:58 01:00 0 0 |05:32:00|93328|5352| |Description 1
05:43:58 01:00 0 0 |05:49:40|99256|5357| |Description 2
05:44:58 00:30 0 0 |05:50:40|99301|5358| |Description 3
06:09:37 01:00 0 0 |06:10:00|58181|0348| |Description C
タイムスタンプは、例えば最初の8列、次のとおりです。これは私が持っているコードですが、それが唯一の区切り文字を使用して、同じ行にファイルを追加し、することができます
05:37:58
05:43:58
05:44:58
:ファイルsample_A.txtオン 私は助けをお願いしますか?
ありがとうございました。
string[] files = new string[] { @"c:\temp\sample_A.txt", @"c:\temp\sample_B.txt" };
var hash = new Dictionary<string, Dictionary<string, bool>>();
foreach (var file in files)
{
string[] fileContents = File.ReadAllLines(file);
foreach (string line in fileContents)
{
string[] a = line.Split('|');
if (!hash.Keys.Contains(a[0]))
hash[a[0]] = new Dictionary<string, bool>();
hash[a[0]][a[1]] = true;
}
}
foreach (var key in hash.Keys)
Console.WriteLine(key + "," + string.Join(",", hash[key].Keys.ToArray()));
ありがとう、これは実際に動作します! – AJ152