c++ - QChar get digit value if `isDigit()` -
how digits value elegantly?
qchar qc('4'); int val=-1; if(qc.isdigit()){ val = qc.tolatin1() - '0'; }
does not good.
neither converting qstring
since creating qstring object , start parsing purpose seems overkill.
qchar qc('4'); int val=-1; if(qc.isdigit()){ val = qstring(qc).toint(); }
any better options or interfaces have missed?
there method int qchar::digitvalue() const
which:
returns numeric value of digit, or -1 if character not digit.
so, can write:
qchar qc('4'); int val = qc.digitvalue();
wiki
Comments
Post a Comment