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?
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.
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.
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.
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.
You have to do it like this:
If strMyString.Contains("Something") OrElse strMyString.Contains("Something2") Then '[Put Code Here] End if
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With