how to trim or normalize a QString?
-
@KroMignon said in how to trim or normalize a QString?:
the easiest way is:
I disagree, the easiest way is to use
https://doc.qt.io/qt-5/qstring.html#trimmed
or
https://doc.qt.io/qt-5/qstring.html#simplified;-)
edit:
forgot the comma requirement:
https://doc.qt.io/qt-5/qstring.html#replace-3 -
@opengpu
well yes, and no.If your goal is to have all normal chars in a QStringList, than using @KroMignon split with the extra argument is probably faster and easier:
auto list = myString.split(',' , QString::SkipEmptyParts);
-
@opengpu said in how to trim or normalize a QString?:
mainly remove the space and comma.
Oups, I think a read/reply too quickly your question: perhaps is should be:
auto listParts = myString.split(QRegExp(" |,"), QString::SkipEmptyParts);
This will remove all spaces and coma and generate a list with the elements.
perhaps a better implementation could beauto listParts = myString.remove(' ').split(',');
So you could get also empty elements.
-
@KroMignon said in how to trim or normalize a QString?:
auto listParts = myString.split(QRegExp(" |,"), QString::SkipEmptyParts);
QRegExp
is deprecated; I suggestQRegularExpression
instead.