[Qt-interest] how to extract the number from QString

Dan White ygor at comcast.net
Fri May 21 16:14:10 CEST 2010


QString has sprintf and vsprintf.  Why not sscanf ?  Or did I miss it in the documentation ?

“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)

----- Oliver Knoll <Oliver.Knoll at comit.ch> wrote:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list