How to check if a String contains any of some strings

Well, there’s always this: public static bool ContainsAny(this string haystack, params string[] needles) { foreach (string needle in needles) { if (haystack.Contains(needle)) return true; } return false; } Usage: bool anyLuck = s.ContainsAny(“a”, “b”, “c”); Nothing’s going to match the performance of your chain of || comparisons, however.

String contains – ignore case [duplicate]

You can use org.apache.commons.lang3.StringUtils.containsIgnoreCase(CharSequence str, CharSequence searchStr); Checks if CharSequence contains a search CharSequence irrespective of case, handling null. Case-insensitivity is defined as by String.equalsIgnoreCase(String). A null CharSequence will return false. This one will be better than regex as regex is always expensive in terms of performance. For official doc, refer to : StringUtils.containsIgnoreCase Update … Read more

Check if a value exists in ArrayList

Just use ArrayList.contains(desiredElement). For example, if you’re looking for the conta1 account from your example, you could use something like: if (lista.contains(conta1)) { System.out.println(“Account found”); } else { System.out.println(“Account not found”); } Edit: Note that in order for this to work, you will need to properly override the equals() and hashCode() methods. If you are … Read more

Search for “does-not-contain” on a DataFrame in pandas

You can use the invert (~) operator (which acts like a not for boolean data): new_df = df[~df[“col”].str.contains(word)] where new_df is the copy returned by RHS. contains also accepts a regular expression… If the above throws a ValueError or TypeError, the reason is likely because you have mixed datatypes, so use na=False: new_df = df[~df[“col”].str.contains(word, … Read more

Java List.contains(Object with field value equal to x)

Streams If you are using Java 8, perhaps you could try something like this: public boolean containsName(final List<MyObject> list, final String name){ return list.stream().filter(o -> o.getName().equals(name)).findFirst().isPresent(); } Or alternatively, you could try something like this: public boolean containsName(final List<MyObject> list, final String name){ return list.stream().map(MyObject::getName).filter(name::equals).findFirst().isPresent(); } This method will return true if the List<MyObject> contains … Read more

How to check if a string contains text from an array of substrings in JavaScript?

There’s nothing built-in that will do that for you, you’ll have to write a function for it, although it can be just a callback to the some array method. Two approaches for you: Array some method Regular expression Array some The array some method (added in ES5) makes this quite straightforward: if (substrings.some(function(v) { return … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)