I'm trying to remove all items inside a list that contain a certain last name in c#.
I don't really have any code to show as I've just been researching how to do it and I can't find solutions anywhere.
Input with be in format of "First Last" I can't change that.
List<string> people = new List<string>();
people.Add("Tommy Chan");
people.Add("Taylor Chan");
List<string> contain = new List<string>();
foreach (string s in people)
{
if (s.Contains("Chan"))
{
//Remove Item from list here
Console.WriteLine("Removed");
}
else
{
Console.WriteLine("Doesn't Contain Chan");
}
}
Console.ReadKey();
This is just needed for a project where it takes a list of peoples names and groups them by last name giving the ability to remove all with a certain last name. I can't seem to find anywhere where I can search an entire List by find a certain amount in the list. I've found lots of different loops but they all require it to exact match the entire string.
Thanks