C# compare 2 files contents for matches

sandrine10

Power Member
Joined
Apr 14, 2010
Messages
779
Reaction score
88
I am trying to find a way to compare some text in 2 files and if a match is found .

Here are examples of the files;

'File A'

example1,textA,intA
example2,textA,intA
example3,textA,intA
example4,textA,intA
...

'File B'

example1,textB,intB
exampleA,textB,intB
exampleB,textB,intB
example4,textB,intB
...
Using my 2 example files, I want to search them both and find matches(i mean example1 & example4)??!
 
load file1 as list
load file2 as list

then you can just loop through and see if match.

foreach(var line in list1){
if(list2.Contains(line)) {
//got a match
}
}

Or you could do some linq

list1.Where(x=>list2.contains(x))
 
Didn't work as i'm looking for matches substrings once found want write the whole line of each match found in fileA !
 
Do you want to compare line by line? I mean first line with first line and so on?
 
Back
Top