ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ContainsAny

Checks if a given string contains any of the string array.

Source

public static bool ContainsAny(
	this string value,
	params string[] values)
{
	foreach (string one in values)
	{
		if (value.Contains(one))
		{
			return true;
		}
	}
	return false;
}

Example

string value = "Kevin from Taiwan.";
string[] values = new string[] { "Kevin", "Sunny" };
if(value.ContainsAny(values))
{
	Console.WriteLine("Hi!");
}

Author: kevinjong

Submitted on: 24 mrt. 2010

Language: C#

Type: System.String

Views: 8061