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

ContainsAll

Check whether the specified string contains an array of strings for each.

Source

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

Example

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

Author: kevinjong

Submitted on: 24 mrt 2010

Language: C#

Type: System.String

Views: 3617