Remove strings contained in one QStringList, from another QStringList
-
07-03-2021 - |
Question
I was wondering if anyone knew of a Qt library method that can take two QStringList
and remove all of the strings contained in one list from the second list.
Solution
You could use the QList::toSet()
method and do some my_set1.substract(my_set2)
, and then go back QSet::toList()
.
But this is just to play around with conversion code. You'd better code the logic yourself with the given lists, it will be faster and won't involve useless memory allocation (even if temporary)
OTHER TIPS
There is no library function in QList
nor QStringList
.
But you can write your own method:
void remove(QStringList& list, const QStringList& toDelete){
QStringListIterator i(toDelete);
while(i.hasNext()){
list.removeAll(i.next());
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow