1、
QString str = " ad dfdsf ef okkd ikk";
str.remove(QRegExp("\\s"));
qDebug()<<str.remove(QRegExp("\\s"));
"addfdsfefokkdikk"
2、
还有去掉前后的空白符
Example:
QString str = " lots\t of\nwhitespace\r\n ";
str = str.simplified();
// str == "lots of whitespace";
3、
Example:
QString str = " lots\t of\nwhitespace\r\n ";
str = str.trimmed();
// str == "lots\t of\nwhitespace"
这三个方法都不一样。