1、一個字符串,一個字符串數組。判斷字符串數組裏的元素出如今字符串中的有幾個。javascript
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(); } }