C# 获取字符串数组中包含某个字符的元素的个数

比如string[] a={a b c ,a a c ,a c c ,a e c};

如何获取字符串数组a中 包含b字符的元素个数

 static void Main(string[] args){

         string[] a={"abc","aac","acc","aec"};
         int count = 0;
         foreach (var item in a)
         {
             if(item.Contains("b")) count++;
         }
         Console.WriteLine(count);
        }

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-10-30
        //using System.Linq;
        static void Main(string[] args)
        {
            string[] a = { "ab", "ac", "b", "ac", "bc", "c" };
            int bcnt = a.Count(x => x.Contains("b"));
            Console.WriteLine(bcnt);//3
            Console.ReadLine();
        }

第2个回答  2014-10-31
private int Function(string[] strArr, char b)
{
   return (from q in strArr
               where q.Contains(b)
               select q).Count();
}

第3个回答  2014-11-05
 int count = 0;
            for (int i = 0; i < a.Length; i++)
                if (a[i].Contains("b"))
                    count++;

第4个回答  2014-10-31
int nResult = a.Where(c => c == "b").ToArray().Length;
nResult就是

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网