如何使用string.Endswith测试多个结尾? [英] How to use string.Endswith to test for multiple endings?
本文介绍了如何使用string.Endswith测试多个结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从以下任意一个运算符中检入 string.Endswith()
: +,-,*,/
I need to check in string.Endswith("")
from any of the following operators: +,-,*,/
如果我有20个运算符,则我不想使用 || 运算符
If I have 20 operators I don't want to use ||
operator 19 times.
推荐答案
如果您使用的是.NET 3.5,则使用LINQ相当容易:
If you are using .NET 3.5 then it is quite easy with LINQ:
string test = "foo+";
string[] operators = { "+", "-", "*", "/" };
bool result = operators.Any(x => test.EndsWith(x));
这篇关于如何使用string.Endswith测试多个结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文