Monday, 15 February 2010

java - Boolean expression for string to have at least one of multiple substrings -



java - Boolean expression for string to have at least one of multiple substrings -

i need check string field see if contains @ to the lowest degree 1 of 2 different substrings. should either contain "abc" or "xyz". if not, setting error. current code:

if(usertitle!=null && !usertitle.contains("abc")){//error}

how expand check if contains "abc" or "xyz"?

if(usertitle != null && !(usertitle.contains("abc") || usertitle.contains("xyz"))

this status want.

best way write such things write in natural language: "if not contain ( abc or xyz ) then.."

the resulting look can simplified using de morgan's laws. search , certainly find easy explanation of them somewhere.

java

No comments:

Post a Comment