[Qt-interest] how to extract the number from QString
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Fri May 21 14:46:46 CEST 2010
Eirik Ulvik wrote on Friday, May 21, 2010 2:37 PM:
> Den 21.05.2010 14:33, skrev hakiim the dream:
>> Hi all, suppose that I have the string abc001. I have to seperate the
>> characters from the numeric part ...
> You can iterate over all characters in the string and use
> QChar::isNumber (http://doc.qt.nokia.com/4.6/qchar.html#isNumber).
QRegExp is your friend, too. If your string is *always* of the form 'abc001' (i.e. exactly 3 letters followed by 3 digits), off course the easiest solution would be to just say
QString myString("abc001");
QString number = myString.mid(3); // number = "001"
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list