My Object returns me -
from
Log.d("FormattedDate", Object.getDOB());
if (!Object.getDOB().matches("[^-]*")) {
txtDOB.setText(Object.getDOB());
} else {
txtDOB.setText("-");
}
I am checking if my Object.getDOB() matches with -
, then show emptry strings, but this regExp is not working.
java.lang.String has a String#contains() method that does this for you:
Returns true if and only if this string contains the specified sequence of char values.
if (Object.getDOB().contains("-")) {
//code
}
You could also use
if (Object.getDOB().indexOf("-") != -1) {
//code
}
if it returns -1
then the string does not contain the char (in your case "-"
). Otherwise it returns the index of the char.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With