How do I remove trailing whitespace from a QString?

前端 未结 9 1798
甜味超标
甜味超标 2020-12-29 19:24

I want to remove all the trailing whitespace characters in a QString. I am looking to do what the Python function str.rstrip() with a QString

9条回答
  •  别那么骄傲
    2020-12-29 19:36

    This is a variation of the answer posted by Frank S. Thomas:

    QString rstrip(const QString& str, const char *skip = " \r\n\t") {
      int n = str.size() - 1;
      for (; n >= 0; --n) {
        if (0 == strchr(skip, str.at(n).toAscii()))
          return str.left(n + 1);
      }
      return "";
    }
    

提交回复
热议问题