一、一个字符串,一个字符串数组。判断字符串数组里的元素出现在字符串中的有几个。

Linq to object 技巧、用法集锦
    class Program
    {
        static void Main(string[] args)
        {
            string str = "你在他乡还好吗?";
            string[] WordList = new string[] {"他乡","家庭","还好","怎么" };
            int count = WordList.Where(m => str.Contains(m)).Count();

            Console.WriteLine(count);   //输出2

            Console.ReadKey();
        }
    }
Linq to object 技巧、用法集锦

 

 
 
框架:Linq学习笔记
 
粉丝 - 664
 
 
0
0
 
(请您对文章做出评价)
 

一、一个字符串,一个字符串数组。判断字符串数组里的元素出现在字符串中的有几个。

Linq to object 技巧、用法集锦
    class Program
    {
        static void Main(string[] args)
        {
            string str = "你在他乡还好吗?";
            string[] WordList = new string[] {"他乡","家庭","还好","怎么" };
            int count = WordList.Where(m => str.Contains(m)).Count();

            Console.WriteLine(count);   //输出2

            Console.ReadKey();
        }
    }
Linq to object 技巧、用法集锦

 

相关文章:

  • 2022-01-29
  • 2021-09-10
  • 2022-12-23
  • 2021-12-01
  • 2021-10-10
  • 2021-08-29
猜你喜欢
  • 2021-11-08
  • 2022-12-23
  • 2022-02-14
  • 2021-08-07
  • 2021-05-20
相关资源
相似解决方案