我正在努力使这项工作,但似乎不被接受。是否有任何修复或解决方法?
switch(email){
case (email.contains('acceptall')):
log.info email
break
default:
log.info "Doesn't work!"
}
我在 SoapUI 中使用 groovy 作为脚本
最佳答案
使用正则表达式,大致:
switch (email) {
case ~/.*acceptall.*/:
log.info(email)
break;
default:
log.info("Doesn't work!")
}
http://groovy.codehaus.org/Logical+Branching#LogicalBranching-switchstatement
Switch supports the following kinds of comparisons
- Class case values matches if the switchValue is an instanceof the class
- Regular expression case value matches if the string of the switch
- Value matches the regex Collection case value matches if the switch
- Value is contained in the collection. This also includes ranges too (since they are Lists)
- if none of the above are used then the case value matches if the case value equals the switch value
关于groovy - 可以切换使用String.contains吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25666635/