I've got two files
"Database.txt" contains the following names:
- Dog
- Cat
- Mouse
- Panda
- Bear
"Slave.txt" contains the following names:
Cat
Panda
I want to compare the "Slave.txt" with "Database.txt" and create third file with:
2. Cat 4. Panda
(Cat and Panda from Slave.txt find in Database.txt)
My code:
static void Main(string[] args)
{
String directory = @"C:\Users\user\Desktop\";
String[] linesA = File.ReadAllLines(Path.Combine(directory, "Database.txt"));
String[] linesB = File.ReadAllLines(Path.Combine(directory, "Slave.txt"));
IEnumerable<String> onlyB = linesB.Intersect(linesA);
File.WriteAllLines(Path.Combine(directory, "Result.txt"), onlyB);
}
works only on Database.txt structure like:
Dog
Cat
Mouse
Panda
Bear
without line numbers. Is there somethink instead .Intersect to find only part of string, not full string?
.Where(predicate func)