JOE SKEET
JOE SKEET

Reputation: 8098

delete everything from List<string> with specific string

i have:

List<string> MyFiles

i need to delete everything from this list that has a specific string inside of it

for example if the list was:

alex1
alex123
alex234
alex345

and i would like to delete every element in this list that has the string "1" in it?

Upvotes: 2

Views: 279

Answers (2)

Code Maverick
Code Maverick

Reputation: 20415

Does this work for you?

C#

MyFiles.RemoveAll((string s) => s.Contains("1"))

I code in VB.NET:

MyFiles.RemoveAll(Function(s As String) s.Contains("1"))

Upvotes: 1

manji
manji

Reputation: 47978

MyFiles.RemoveAll(s => s.Contains("1"));

Upvotes: 8

Related Questions