c++ - Find a number inside a QString -
i have qstring number inside it, example
first_34.33string second-23.4string // in case number negative
how can extract number string?
edit:
this function seems work, using regexp in replies:
float getnumberfromqstring(const qstring &xstring) { qregexp xregexp("(-?\\d+(?:[\\.,]\\d+(?:e\\d+)?)?)"); xregexp.indexin(xstring); qstringlist xlist = xregexp.capturedtexts(); if (true == xlist.empty()) { return 0.0; } return xlist.begin()->tofloat(); }
this should work valid numbers: qregexp("(-?\\d+(?:[\\.,]\\d+(?:e\\d+)?)?)")
edit: sorry, messed brackets, should work.
Comments
Post a Comment