I need to check in string.Endswith("")
from any of the following operators: +,-,*,/
If I have 20 operators I don't want to use ||
operator 19 times.
If you are using .NET 3.5 (and above) then it is quite easy with LINQ:
string test = "foo+";
string[] operators = { "+", "-", "*", "/" };
bool result = operators.Any(x => test.EndsWith(x));
Although a simple example like that is probably good enough using ||
, you can also use Regex for it:
if (Regex.IsMatch(mystring, @"[-+*/]$")) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With