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

在上面的示例中,我希望字符串列表包含两个条目,但它只包含 1,这与 strTest 相同......为什么拆分不起作用?

我也试过:

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

结果是一样的。

4

2 回答 2

3

解决了:

    QStringList slstLines = strTest.split("\\n");
于 2016-05-16T10:38:28.183 回答
-1

试试这个代码:例如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" ]
于 2016-05-16T10:43:56.817 回答