How do I remove trailing whitespace from a QString?

前端 未结 9 1783
甜味超标
甜味超标 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:47

    If you don't want to make a deep copy of the string:

    QString & rtrim( QString & str ) {
      while( str.size() > 0 && str.at( str.size() - 1 ).isSpace() )
        str.chop( 1 );
      return str;
    }
    

提交回复
热议问题