lundi 29 juin 2020

C++ quickly check if a string contains an integer, a double or just text

I'm writing a telegram bot in c++ and I need to check, for every incoming message, if it contains a number, if it's an integer number or not, or if it doesn't contain any number so I need to do other checks as text.

I was hoping I could use some regular expressions, but I'm unable to find a good answer for my specific situation.

I could run through the characters of the message and check if there is a dot around digits, or even if there is no digit at all, but this check will have to be done for each received message, and I think such a long procedure will really slow down the bot (which already deals with other potentially slow stuff).

I'm using C++11, without the boost library. Is there any faster solution?

Aucun commentaire:

Enregistrer un commentaire