我有一個字符串如何檢查字符串列表是否與短語中的所有單詞匹配?
string[] arr = new string[] { "hello world", "how are you", "what is going on" };
的名單,我需要檢查,如果我給字符串使用的每一個字中的一個字符串在arr
讓我們說,我有
string s = "hello are going on";
這將是一個匹配,因爲s
中的所有單詞都在arr
string s = "hello world man"
這個人會不會是一個比賽,因爲「人」是不是在任何字符串的arr
我知道怎麼寫了「長」的方式來做到這一點,但有一個很好的LINQ查詢,我可以寫嗎?
+1:優雅,簡單,好看。 SelectMany不需要像Nathan和我一樣!你可以像我在我的回答中那樣使用函數或Func委託來事件一行。 – Larry 2013-03-13 19:18:42