Some alternative solution employing some IEnumerable<strin> extension methods plus some LINQ syntax:
- Concat(), Aggregate()
- from ... in ... let d = ... orderby d ascending select d
public static void MergeFiles(string in1, string in2, string merge)
{
var q = from t in File.ReadAllLines(in1).Concat(File.ReadAllLines(in2))
let d = t.Substring(t.IndexOf('|')+1) orderby d ascending
select d;
using (StreamWriter w = new StreamWriter(merge))
q.Aggregate(0, (a, d) => { w.WriteLine("{0}|{1}", ++a, d); return a; });
}
- Create a query that returns all truncated lines of both files (stripped off initial "...|"), sorted.
- process all lines and write to the stream, by counting the line number (the aggregation value).
Cheers
Andi