compare a row with a file
I want to make a compare procedure in my code that takes a text file that has 开发者_开发知识库names (one under the other) and compares them with a row of names.
For example : row_example row is:
george
nick
gregory
samantha
And the input file with the names (names.txt) is :
micheal
john
george
mary
jennifer
oliver
jack
harry
alfie
The program will take the first one given from the text file(micheal) and search the row. After will take the next name from the text file given(john) and search the row. etc... etc.. It will print a message with the names of the row that where not found.
Is this what you are looking for ?
private string Compare()
{
string[] compareAgainst = File.ReadAllLines("[file_path]");
string[] row = new string[] { "name1", "name2", "name3", "name4", };
string result = string.Empty;
foreach(string name in compareAgainst)
{
if (row.Contains(name))
result = String.Format(result + " {0}", name);
}
return result;
}
[file_path] - path to text file containing names, one in each line Simply print out the result of this method.
Hope this gives you an idea,
Kris
精彩评论