How can i get more values in a EndsWith?
For example
if(textbox1.Text.EndsWith("hotmail.com" && "anothermail.com"){
}
What to do?
How can i get more values in a EndsWith?
For example
if(textbox1.Text.EndsWith("hotmail.com" && "anothermail.com"){
}
What to do?
You can create an extension method:
public static bool EndsWithAny(this string str, params string[] search)
{
return search.Any(s => str.EndsWith(s));
}
//Call
bool found = str.EndsWithAny("hotmail.com", "anothermail.com");
If you want to get the results where the value ends with one string, or ends with the other string, then combine the two checks with a logical or:
if(textbox1.Text.EndsWith("hotmail.com") || textbox1.Text.EndsWith("anothermail.com")) { ... }
string[] ends = new string[] { "hotmail.com" , "anothermail.com" };
string text = "example.hotmail.com2";
bool endsWith = ends.Any(e => text.EndsWith(e));
You could use a collection and Any
+EndsWith
:
var mails = new[] { "hotmail.com", "anothermail.com" };
bool endsWithAny= mails.Any(textbox1.Text.EndsWith);