Qt - splitting a QString using multiple types of spaces as delimiters

I want to smash a QString. There are several words in QString separated by one or more (!) The following characters:

  • space
  • tab
  • CR
  • Lf

I want to extract only words. Basically, I am trying to replicate the behavior of the Python function str.split ().

I know that you can use a regular expression for this, but what does it look like? Any other simple ways to achieve this are also welcome.

+4
source share
1 answer

, CR, LF . , \s:

\s (QChar::isSpace()).

,

QStringList list = str.split(QRegExp("\\s+"), QString::SkipEmptyParts);

, .

[...] , . , , .

QStringList list = str.split(QRegExp("[\r\n\t ]+"), QString::SkipEmptyParts);

, .

+5

All Articles