LINQ方法:
Dim fruits As New List(Of String) From { "apple", "orange", "pear", "banana" }
Dim input As String = "a,p,l,e,r"
Dim letters As String = input.Replace(",", "")
Dim result = fruits.Where(Function(fruit) Not fruit.Except(letters).Any())
正則表達式的方法:
一個正則表達式匹配的結果將類似於這樣的:
"^[apler]+$"
這可以建立起來的:
Dim fruits As New List(Of String) From { "apple", "orange", "pear", "banana" }
Dim input As String = "n,a,b,r,o,n,g,e"
Dim letters As String = input.Replace(",", "")
Dim pattern As String = "^[" + letters + "]+$"
Dim query = fruits.Where(Function(fruit) Regex.IsMatch(fruit, pattern))
爲什麼蘋果和梨出現而不是其他? – Flash 2011-06-07 12:42:28
輸入字符的順序是否相關?例如。 'a,p,l'與'apple'匹配,但'p,l,a'不?並且:在你的例子中,梨應該真的匹配嗎?因爲你的角色列表中有一個'l'。 – 2011-06-07 12:45:29
因爲用戶沒有輸入o,n,g代表桔子,b代表香蕉,n代表香蕉。這個想法是顯示所有字,已輸入的字符。 – Cobold 2011-06-07 12:45:57