Sidebar

How to use StringUtils.ContainsAny?

0 votes
6.1K views
asked Jul 31, 2018 by joe-d-8335 (180 points)
I see a documented function for StringUtils.ContainsAny but not much information beyond the signature. Does the searchString have to be characters, or can it be whole strings? Does it match by RegEx or something else?

2 Answers

0 votes

StringUtils.ContainsAny will search for any character or number in the search characters list or array of characters. If any one of the characters is found then a boolean value of true will be returned.

StringUtils.contains('abc1', '1') = true
StringUtils.containsAny("zzabyycdxx",['z','y']) = true
StringUtils.containsAny("zzabyycdxx", "zy")    = true

 

answered Jul 31, 2018 by gary-t-8719 (14,860 points)
commented Jul 31, 2018 by joe-d-8335 (180 points)
How about a set of strings instead of a string of chars?

StringUtils.containsAny("zzabyycdxx",["za","zb"])
commented Jul 31, 2018 by mike-r-7535 (13,830 points)
@joe-d, I don't think that will work.  According to https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringUtils.html , containsAny allows for the following parameters: (string, string) or (string, char[]).  There is no containsAny(string, string[]).
0 votes

The search parameter of containsAny must be either an array of characters, or a single string.  This is according to the StringUtils documentation.

None of the StringUtils functions use regular expressions.  Regular expressions can be used with Java Strings or Javascript Strings in QIE.

answered Jul 31, 2018 by mike-r-7535 (13,830 points)
...