I would like to check if a QString
is made up of only non-printable or non-visible characters. The QString
could contain unicode...
I imagine a regular expression may work, but I have no idea how to create such a regex.
How can I check if a QString
contains only "invisible" characters ? (space, \n
, \r
, \t
...)
My "brute force" try
bool checkIfEmpty(const QString &contents) const
{
for(QString::const_iterator itr(contents.begin()); itr != contents.end(); ++itr)
{
if(*itr != '\n' && *itr != '\r' && *itr != ' ' && *itr != '\t')
return false;
}
return true;
}
try this approach
bool checkIfEmpty(const QString contents) const
{
if(contents.trimmed()=="") return true;
else return false;
}
please note that this could be used only if you meant by "no printable" is space or tab characters
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