I have a QString with some number inside it, for example
first_34.33string
second-23.4string // In this case number is negative
How can I extract number from the string?
EDIT:
This function seems to 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 for valid numbers: QRegExp("(-?\\d+(?:[\\.,]\\d+(?:e\\d+)?)?)")
edit: sorry, messed up with the brackets, now it should work.
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