remove all strings from list containing certain substring

c#, list

Solution

You can use `RemoveAll` to get the result:

albumList.RemoveAll(x => x.Split(',')[0].ToString().Equals(search))

For easier to read, you can use:

albumList.RemoveAll(x => x.Split(',').First().Equals(search))

Problem

I've got a list of strings called albumList the string has this structure: abc,abc,abc,abc,abc I ask the user to search an album to delete; if the album is found, it will be deleted from the list. There could be more than one album with the same name to be deleted from the list. ``` private void searchAlbumName(string search) { string[] cellVal; foreach (string x in albumList) { cellVal = x.Split(','); if (cellVal[0].ToString().Equals(search)) { //do delete here } } } ``` I'm not sure how to remove every album with the search name

Original source

Related problems