You are confusing String.Contains
with String.IndexOf
. Compare
returns a Boolean
, not an Integer
, and it doesn't support case-insensitivity. IndexOf
is the one that returns an Integer
and supports case-insensitivity. Also, it's StringComparison
, not StringComparer
. Finally, -1 is the result that indicates no match:
found1 = found.ToString().IndexOf(name, StringComparer.OrdinalIgnoreCase) <> -1
As a bonus, here's an extension method that will let you call a Contains
method that still returns a Boolean
but also supports case-insensitivity:
Imports System.Runtime.CompilerServices
Public Module StringExtensions
<Extension>
Public Function Contains(source As String, value As String, comparisonType As StringComparison) As Boolean
Return source.IndexOf(value, comparisonType) <> -1
End Function
End Module
E.g.
found1 = found.ToString().Contains(name, StringComparer.OrdinalIgnoreCase)