I'll list two different approaches
ContainsWord1() uses:
Enumerable.Any(Of TSource) - .NET 3.5+
Ref: https://msdn.microsoft.com/en-us/library/yw84x8be(v=vs.110).aspx
ContainsWord2() uses:
Array.Exists(Of T) Method (T(), Predicate(Of T)) - .NET 2.0+
Ref: https://msdn.microsoft.com/en-us/library/bb337697(v=vs.110).aspx
Both are case insensitive.
Private Function ContainsWord1(p_wordsArray as string(), p_word As string) as Boolean
return p_wordsArray.Any(Function(s as String) s.Equals(p_word.trim, StringComparison.CurrentCultureIgnoreCase))
End Function
Private Function ContainsWord2(p_wordsArray as string(), p_word As string) as Boolean
return Array.Exists(p_wordsArray, Function(s As String) s.Equals(p_word.trim, StringComparison.CurrentCultureIgnoreCase))
End Function
private Sub ContainsWordExample()
Dim _words = New String(){"blue","red","yellow", "black"}
Dim _yellow as string = "YeLloW"
Dim _green as string = "green"
'Yellow test
If ContainsWord1(_words, _yellow) then
messagebox.Show("You got it!")
Else
messagebox.Show("Try again!")
End If
If ContainsWord2(_words, _yellow) then
messagebox.Show("You got it!")
Else
messagebox.Show("Try again!")
End If
'Green test
If ContainsWord1(_words, _green) then
messagebox.Show("You got it!")
Else
messagebox.Show("Try again!")
End If
If ContainsWord2(_words, _green) then
messagebox.Show("You got it!")
Else
messagebox.Show("Try again!")
End If
End Sub
Containsmethod, but did you consider looking to see it they expose other methods that may help you achieve the goal?answerstring.