QT如何去掉字符串中的空格
1个回答
展开全部
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
;
返回一个字符串,移除从一开始到结尾的空白,每个序列内部的空格替换为一个空格(头尾的都去掉了)
举个例子:[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
;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询