QString strTest = "SHUT\nDOWN";
QStringList slstLines = strTest.split("\n");
在上面的例子中,我希望String列表包含两个条目,但它只包含1,这与strTest相同...为什么不能分割工作?
我也尝试过:
QStringList slstLines = strText.split(QRegExp("[\n]"), QString::SkipEmptyParts);
结果是一样的。
答案 0 :(得分:3)
解决:
QStringList slstLines = strTest.split("\\n");
答案 1 :(得分:-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" ]