【发布时间】:2012-01-03 03:47:33
【问题描述】:
我想删除QString 中的所有尾随空格字符。我正在寻找使用QString 来执行Python 函数str.rstrip() 的操作。
我做了一些谷歌搜索,发现了这个:http://www.qtforum.org/article/20798/how-to-strip-trailing-whitespace-from-qstring.html
所以我现在拥有的是这样的:
while(str.endsWith( ' ' )) str.chop(1);
while(str.endsWith( '\n' )) str.chop(1);
有没有更简单的方法来做到这一点?我想在开头保留所有空格。
【问题讨论】:
-
我认为它的逻辑有缺陷:应该是 while(str.endsWith(' ' ) || str.endsWith( '\n' )) str.chop(1);
-
@chac,是的,它会在这样的字符串上失败:“abc \n \n”