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

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -