0

I have made a software in vb.net that has a specific purpose.

It has to compare two strings at a particular point, say they are x and y. The code is

If x.Contains(y) then
'do things here
End If

If y is 'Hello' and x is 'hello there', then the if statement must be true according to my requirement, but it turns out the Contains() control is case sensitive.

How do I make it case insensitive?

EDIT: My question is in vb.net and not C#. Though they are mostly similar, I do not understand C# and don't know how to implement the answers in my scenario because both of these are different langauages. So my question is not duplicate of the one mentioned.

Kashish Arora
  • 900
  • 5
  • 25
  • 39
  • 2
    @KashishArora - the *framework* is shared by C# and VB.Net and so solutions using *framework* methods will be identical, absent *minor* differences such as VB not ending statements with a `;`. If you can't take the C# answers in the linked question and make them work in VB, that's going to be a *general* issue you need to address because you're far more likely to find *general* solutions written in C# and, as I say, the *framework* is the same for both. – Damien_The_Unbeliever Jun 05 '18 at 14:52
  • 2
    Another case where the [documentation for the method](https://msdn.microsoft.com/en-us/library/dy85x1sa(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#Remarks) provides the solution. – TnTinMn Jun 05 '18 at 15:35

2 Answers2

1
If x.IndexOf(y, StringComparison.CurrentCultureIgnoreCase) >= 0 Then
    'do nothing
End If
PavlinII
  • 1,061
  • 1
  • 7
  • 12
0

Making both x and y to upper case would also work.

If x.ToUpper().Contains(y.ToUpper()) Then
'do things here
End If
Cal-cium
  • 654
  • 12
  • 22