Click here to Skip to main content
15,914,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a better way to check if a string includes different strings? This is my current method but I dont think it will work as I am trying to check it against multiple
Is there a better way to do it? (Non case sensitive)

What I have tried:

If subject.IndexOf("lorem", 0, StringComparison.CurrentCultureIgnoreCase) > -1  Or If
                   subject.IndexOf("ipsum", 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
Posted
Updated 2-Nov-20 4:26am

IndexOf is the only way to check without case sensitivity, but you could use Linq methods:
VB
Dim searchFor As String() = New String() {"lorum", "ipsum"}
Dim contains As Boolean = searchFor.Any(Function(s) data.IndexOf(s, StringComparison.OrdinalIgnoreCase) > 0)
 
Share this answer
 
Quote:
VB.NET
If ... Or If ... Then
You have a syntax error in your If statement:
If...Then...Else Statement - Visual Basic | Microsoft Docs[^]

Try:
VB.NET
If subject.IndexOf("lorem", 0, StringComparison.CurrentCultureIgnoreCase) > -1  OrElse subject.IndexOf("ipsum", 0, StringComparison.CurrentCultureIgnoreCase) > -1 Then
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900