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

这里给大家介绍QString中的两个函数

1.QString QString::simplified() const

Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.

返回一个字符串,移除从一开始到结尾的空白,每个序列内部的空格替换为一个空格(头尾的都去掉了)

举个例子:
 QString str = "  lots\t of\nwhitespace\r\n ";
 str = str.simplified();
 // str == "lots of whitespace";
'\t', '\n', '\v', '\f', '\r', '  ' 都属于空白的处理范围。

2.QString QString::trimmed() const

Returns a string that has whitespace removed from the start and the end.

返回一个字符串,移除从一开始到结尾的空白。也去掉头尾的空白

举个例子:

 QString str = "  lots\t of\nwhitespace\r\n ";
 str = str.trimmed();
 // str == "lots\t of\nwhitespace"



相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页