Qt 去掉QString中的空白字符

1、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"
特此记录!

你可能感兴趣的:(C++,QT)