Reputation: 125
I am trying to create a short Windows Presentation Foundation application in C# to compare two lists in different formats and output the users that are common to them.
Right now I am taking each list from the user via a textbox.
Now I am a little confused on how I can compare the two different textboxes and output the common names. If the data was in an array of some sort I could have used:
var name = string.Split('(')[0].Trim()
But since I decided to use textboxes, I am unsure of how to proceed with this. For example, consider the following two input lists and the expected output:
First List:
Jacqueline Beaurivage (loh Da road);
Bon Van Daht (fary goal lim)
Bon Jobi (ting wei)
Ting Wan (dehtee road);
Second List:
Jacqueline Beaurivage
Bon Van Daht
Expected output:
Jacqueline Beaurivage
Bon Van Daht
Upvotes: 0
Views: 192
Reputation: 60493
var commonNames = firstList
.Select(m => m.Split('(')[0].Trim())
.Intersect(secondList);
with TextBoxes, as pointed by Austin Salonen
var firstList = textBox1.Text.Select(m => m.Split(Environment.NewLine));
var secondList = textBox2.Text.Select(m => m.Split(Environment.NewLine));
resultTextBox.Text = string.Join(Environment.NewLine,
firstList
.Select(m => m.Split('(')[0].Trim())
.Intersect(secondList));
Upvotes: 5