Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Multiple String Contains [duplicate]

Tags:

c#

Basically I want to detect more than one string, current code example is

if (!str3.Contains("example1"))
{
    continue;
}

How would I add " example1 ", " example2 " & " example3 "

like image 537
wolf pkrs Avatar asked Mar 08 '26 11:03

wolf pkrs


1 Answers

You can use Linq if you want to test with a large list:

var excludes = new[] { "example1", "example2", "example3" };

//your loop here
{
    if (!excludes.Any(x => str3.Contains(x)))
    {
        continue;
    }
}
like image 81
Flat Eric Avatar answered Mar 10 '26 23:03

Flat Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!