Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Filter characters from a string



  • Hello !

    I am working on a client app that communicates with a device via ethernet over TCP.
    I send it a string command and i get back a string response.

    Among the commands and answers, there are control characters and meta-codes. Those are the ASCII characters between 0x60 and 0x7f.

    How can i chop every character within this range from my response string ?

    thanks a lot.



  • @Marty said:

    Among the commands and answers, there are control characters and meta-codes. Those are the ASCII characters between 0x60 and 0x7f.

    How can i chop every character within this range from my response string ?

    Brute force can help there. Since you know the ASCII range to exclude you can simply do it with an if statement. Also the good old C routines might help isalpha and fellows.

    Alternative for more sophisticated stuff there is QRegExp or the newer version QRegularExpression.



  • hum... i imagined there was an easier way to achieve this, like removing a bunch of character at once
    but thanks ! i will have a look



  • Regular expression would be the right choice then. However, you need to be prepared that there is certainly a learning curve.



  • yes, this seems a good way to go.
    now all i see is filtering by matching a pattern
    i don't have any fixed pattern, i would like to remove characters wherever they appear in the string


Log in to reply