Get last element of QStringList
我有这样的
1 2 3 | daily-logs.06-01-2015.01 daily-logs.06-01-2015.02 daily-logs.06-01-2015.03 |
现在我想获取新的
02
03
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | QStringList list = folder_file.entryList(nameFilter); for(int i=0;i<list.count();i++){ qDebug()<<list.at(i).toLocal8Bit().constData(); QStringList list2=list.at(i).split("."); for(int j=0;j<list2.count();j++){ //qDebug()<<list2.at(j).toLocal8Bit().constData(); QString list3=list2.value(list2.length()-1); qDebug()<<list3; //qDebug()<<list3; } |
我只能得到最后的值。 但是我认为这更多是为了循环。 所以没有人有办法获得更高的性能。
使用特殊文件
1 2 3 4 | const auto& list = folder_file.entryList(nameFilter); QStringList output; for(const auto& f : list) output << QFileInfo(f).suffix(); |
您的代码太脏了...
1 2 3 4 5 6 7 8 9 10 11 12 13 | QStringList DoSomeDirtyWork( const QStringList& input ) { QStringList output; for ( auto it = input.constBegin(); it != input.constEnd(); ++it ) { const QString& src = *it; const int pos = src.lastIndexOf('.'); output << src.mid( pos ); } return output; } |
1 2 3 4 5 | QStringList list = folder_file.entryList(nameFilter); for (int i = 0; i < list.count(); ++i) { QStringList wordList = list[i].split('.'); qDebug() << wordList.takeLast(); } |
也许它不是那么可爱和简短,但是它是没有QFileInfo的示例。