How can I tell if a VARCHAR variable contains a substring?
The standard SQL way is to use like: where @stringVar like ‘%thisstring%’ That is in a query statement. You can also do this in TSQL: if @stringVar like ‘%thisstring%’
The standard SQL way is to use like: where @stringVar like ‘%thisstring%’ That is in a query statement. You can also do this in TSQL: if @stringVar like ‘%thisstring%’
You could achieve this by using the List.Contains method: if(new []{1, 2, 3}.Contains(x)) { //x is either 1 or 2 or 3 }
Your best bet is to use a HashSet and check if a string exists in the set via the contains() method. HashSets are built for fast access via the use of Object methods hashCode() and equals(). The Javadoc for HashSet states: This class offers constant time performance for the basic operations (add, remove, contains and … Read more
There is a method called containsAll declared in the java.util.Collection interface. In your setting one.containsAll(two) gives the desired answer.
Turns out it is really easy, the following does the job here: >>> ((df[‘A’] == 2) & (df[‘B’] == 3)).any() True >>> ((df[‘A’] == 1) & (df[‘B’] == 2)).any() False Maybe somebody comes up with a better solution which allows directly passing in the array and the list of columns to match. Note that the … Read more
Why not use Enum.IsDefined(typeof(myEnum), value); BTW it’s nice to create generic Enum<T> class, which wraps around calls to Enum (actually I wonder why something like this was not added to Framework 2.0 or later): public static class Enum<T> { public static bool IsDefined(string name) { return Enum.IsDefined(typeof(T), name); } public static bool IsDefined(T value) { … Read more
If you want to do it with maximum efficiency, you may have to write it yourself (or find a good substring searching algorithm somewhere). If you just want it to work at all, then in Scala: scala> “Finding needle in haystack” contains “needle” res0: Boolean = true scala> “Finding needle in haystack” indexOf “needle” res1: … Read more
Correct final syntax for [Mr. C]s answer. With the release of VS2017RC and its C#7 support it works this way: switch(message) { case string a when a.Contains(“test2”): return “no”; case string b when b.Contains(“test”): return “yes”; } You should take care of the case ordering as the first match will be picked. That’s why “test2” … Read more
Answer To find li‘s that have text containing BOTH Mary AND John: $(‘li:contains(“Mary”):contains(“John”)’) To find li‘s that have text containing EITHER Mary OR John: $(‘li:contains(“Mary”), li:contains(“John”)’) Explanation Just think of the :contains as if it was a class declaration, like .class: $(‘li.one.two’). // Find <li>’s with classes of BOTH one AND two $(‘li.one, li.two’). // … Read more
XPath 1.0 doesn’t handle regex natively, you could try something like //*[starts-with(@id, ‘sometext’) and ends-with(@id, ‘_text’)] (as pointed out by paul t, //*[boolean(number(substring-before(substring-after(@id, “sometext”), “_text”)))] could be used to perform the same check your original regex does, if you need to check for middle digits as well) In XPath 2.0, try //*[matches(@id, ‘sometext\d+_text’)]