QT如何去掉字符串中的空格

如题所述

1.QString QString::simplified() const
返回一个字符串,移除从一开始到结尾的空白,每个序列内部的空格替换为一个空格(头尾的都去掉了)
举个例子:[cpp]
<SPAN style=FONT-SIZE: 18px QString str = lots\t of
whitespace\r
;
str = str.simplified();
// str == lots of whitespace;</SPAN
QString str = lots\t of
whitespace\r
;
str = str.simplified();
// str == lots of whitespace;'\t', '
', '\v', '\f', '\r', ' ' 都属于空白的处理范围。
2.QString QString::trimmed() const
Returns a string that has whitespace removed from the start and the end.
返回一个字符串,移除从一开始到结尾的空白。也去掉头尾的空白举个例子:[cpp]
<SPAN style=FONT-SIZE: 18px QString str = lots\t of
whitespace\r
;
str = str.trimmed();
// str == lots\t of
whitespace</SPAN
QString str = lots\t of
whitespace\r
;
温馨提示:答案为网友推荐,仅供参考
相似回答