如何检查字符数组中是否存在特定字符 [英] How to check if a particular character exists within a character array
本文介绍了如何检查字符数组中是否存在特定字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在C#程序中使用数组,如下所示:
I am using an array within a C# program as follows:
char[] x = {'0','1','2'};
string s = "010120301";
foreach (char c in s)
{
// check if c can be found within s
}
如何检查每个字符c以查看是否在字符数组x中找到了它?
How do I check each char c to see if it is found within the character array x?
推荐答案
if (x.Contains(c))
{
//// Do Something
}
使用.NET 3.0/3.5;您将需要一个using System.Linq;
Using .NET 3.0/3.5; you will need a using System.Linq;
仁慈
丹
这篇关于如何检查字符数组中是否存在特定字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文