Help With if statement

How come the if is true in the statement for a blank variable ‘msg’? I would like it not enter the if, if i get a reply of ping, empty and null. Here is the dubug output.

7:42:15 PM: debug Parse got ‘’

def parse(String description) {
def msg = zigbee.parse(description)?.text
log.debug "Parse got ${msg}"
if (msg != ‘ping’ && msg != “” && msg != null){

Didn’t work and yes I think I want AND. I want everything but ping and nothing.

Even groovier is:

if (["", "ping"].contains(msg)) {
  // contains
} else {
  // does not contain
}


And the above works fine too (you can test it the groovy web console or from your favorite groovyc http://groovyconsole.appspot.com/)

1 Like

That worked Josh. Thanks. Anybody know why my code didn’t work?