Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET - If string contains "value1" or "value2"

I'm wondering how I can check if a string contains either "value1" or "value2"? I tried this:

If strMyString.Contains("Something") Then  End if 

This works, but this doesn't:

If strMyString.Contains("Something") or ("Something2") Then  End if 

This gives me the error that conversion from string to Long can't be done. If I put the or ("Something2") inside the parenthesis of the first one, it gives me the error that the string cannot be converted to Boolean.

So how can I check if the string contains either "string1" or "string2" without having to write too much code?

like image 672
Kenny Bones Avatar asked Jun 16 '11 09:06

Kenny Bones


People also ask

How do you check if a string contains a substring vb net?

contains method in vb.net. Contains method of the string class determine that the substring is present inthe string or not, or we can say contains method checks whether specified parameter string exist inthe string or not. this method returns boolean type value true and false.

How do you check if a string contains a certain string?

You can use contains(), indexOf() and lastIndexOf() method to check if one String contains another String in Java or not. If a String contains another String then it's known as a substring. The indexOf() method accepts a String and returns the starting position of the string if it exists, otherwise, it will return -1.

How do you check if a string contains a symbol?

Use the String. includes() method to check if a string contains a character, e.g. if (str. includes(char)) {} . The include() method will return true if the string contains the provided character, otherwise false is returned.

How do I find a particular character in a string in VB net?

The IndexOf method returns the location of the first character of the first occurrence of the substring. The index is 0-based, which means the first character of a string has an index of 0. If IndexOf does not find the substring, it returns -1. The IndexOf method is case-sensitive and uses the current culture.


1 Answers

You have to do it like this:

If strMyString.Contains("Something") OrElse strMyString.Contains("Something2") Then     '[Put Code Here] End if 
like image 196
Rifky Avatar answered Oct 29 '22 21:10

Rifky