How would I check if a value is in a string array?
Like say there is pages(10) and pages(5) is "rhijaen"
I want it to do something like:
If "rhijaen" isin pages() then
dothis
end if
Printable View
How would I check if a value is in a string array?
Like say there is pages(10) and pages(5) is "rhijaen"
I want it to do something like:
If "rhijaen" isin pages() then
dothis
end if
Code:If pages.Contains("rhijaen") Then
'Do something
End If
This gives me the error: 'contains' is not a member of 'System.Array'.Quote:
Originally Posted by MaximilianMayrhofer
Please post your code.
You probably want to think about using a generic collection, for example a List(of String), rather than an array. It also offers you greater manipulative methods.
If the worst comes to the worst, you can simply iterate through the collection and compare the strings.
(Another alternative may be a LINQ query).
Works just fine for me!
Code:Dim pages() As String = New String() {"Hello"}
If pages.Contains("Hello") Then _
Console.WriteLine("It worked!")
Console.ReadLine()
That Contains method wasn't implemented until 3.5.
Check out this link for details on how to make it work, pre-3.5.
http://www.dotnettoad.com/index.php?....Contains.html
cope snippet...
CType(strYourStringArray, IList).Contains(strYourCheckValue)
Although this is old, you can use the Array.IndexOf method to do the same as contains. If it returns greater then -1 then that means true.