我想刪除QString
中的所有尾部空白字符。我正在尋找做什麼Python函數str.rstrip()
與QString
。如何從QString中刪除尾隨空白?
我做了一些谷歌搜索,發現這樣的: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); – CapelliC
@chac,是的,它會失敗,像這樣的字符串:「abc \ n \ n」 –