4
QString strTest = "SHUT\nDOWN";
QStringList slstLines = strTest.split("\n");

In the above example I would expect the String list to contain two entries, but it only contains 1, which is the same as the strTest...why isn't split working?

I've also tried:

QStringList slstLines = strText.split(QRegExp("[\n]"), QString::SkipEmptyParts);

The result is the same.

demonplus
  • 5,613
  • 12
  • 49
  • 68
SPlatten
  • 5,334
  • 11
  • 57
  • 128

2 Answers2

3

Solved:

    QStringList slstLines = strTest.split("\\n");
SPlatten
  • 5,334
  • 11
  • 57
  • 128
-1

Try this code: for example split:

#include <QString>
#include <QDebug>
...
QString str = "SHUT\nDOWN";
QStringList list = str.split("\n");
qDebug() << list;
//output: ("SHUT", "DOWN")

/////

QString str = "a\n\nb,\n";

QStringList list1 = str.split("\n");
// list1: [ "a", "", "b", "c" ]

QStringList list2 = str.split("\n", QString::SkipEmptyParts);
// list2: [ "a", "b", "c" ]
proton
  • 329
  • 3
  • 10