M
mp
Is there a way to make String.Contains do a case insensitive comparison?
like an equivalent of vb6 Option CompareText in a code module?
I've read the help on the overload of .Contains that uses a
IEqualityComparer object but don't understand how to make that work
from the help:
<quote
This interface allows the implementation of customized equality comparison
for collections. That is, you can create your own definition of equality for
type T, and specify that this definition be used with a collection type that
accepts the IEqualityComparer<(Of <(T>)>) generic interface. In the .NET
Framework, constructors of the Dictionary<(Of <(TKey, TValue>)>) generic
collection type accept this interface.
end quote>
but i'm comparing a string and a substring rather than a collection so don't
know enough how to translate that to
for example in the following snippet how can i eliminate the else if by
making the comparison case insensitive
particularly if the string is not hard coded but comes from a run time
variable
string line;
//populate line variable
//look for substring
if (line.Contains("defun" ))
{
listBox1.Items.Add(line);
}
else if (line.Contains("Defun"))
{
listBox1.Items.Add(line);
}
like an equivalent of vb6 Option CompareText in a code module?
I've read the help on the overload of .Contains that uses a
IEqualityComparer object but don't understand how to make that work
from the help:
<quote
This interface allows the implementation of customized equality comparison
for collections. That is, you can create your own definition of equality for
type T, and specify that this definition be used with a collection type that
accepts the IEqualityComparer<(Of <(T>)>) generic interface. In the .NET
Framework, constructors of the Dictionary<(Of <(TKey, TValue>)>) generic
collection type accept this interface.
end quote>
but i'm comparing a string and a substring rather than a collection so don't
know enough how to translate that to
for example in the following snippet how can i eliminate the else if by
making the comparison case insensitive
particularly if the string is not hard coded but comes from a run time
variable
string line;
//populate line variable
//look for substring
if (line.Contains("defun" ))
{
listBox1.Items.Add(line);
}
else if (line.Contains("Defun"))
{
listBox1.Items.Add(line);
}