Wes Wes - 1 year ago 94
C++ Question

How to detect if a QString is made up of all numeric characters?

What do you guys think is the best way to tell if a QString is made up of just numbers?

There doesn't appear to be a convenience function in the QString library.

Do I have to iterate over every character, one at a time, or is there a more elegant way that I haven't thought of?

sth sth
Answer Source

You could use a regular expression, like this:

QRegExp re("\\d*");  // a digit (\d), zero or more times (*)
if (re.exactMatch(somestr))
   qDebug() << "all digits";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download