QStringList类是QList的派生类,是字符串的列表类。它是一个非常有用的类,在处理字符串时使用QStringList,有时能事半功倍。
QStringList可以使用QList的所有方法,如:append(), prepend(), insert(), replace(), removeAll(), removeAt(), removeFirst(), removeLast(), and removeOne()。
示例:
- #include <QStringList>
- #include <QTextStream>
-
-
- static QTextStream cout(stdout, QIODevice::WriteOnly);
- int main(int argc, char *argv[])
- {
- QString str = "1,2,3,4,5,6,7,8,9";
- QStringList strList;
-
- strList = str.split(",");
-
- cout << "String list item count: " << strList.size() << endl;
-
- for(int i = 0; i < strList.size(); i++)
- cout << i + 1 << ":" << strList[i] << endl;
-
- QString str2;
- str2 = strList.join(",");
-
- cout << str2 << endl;
-
- return 0;
- }