从一个 QStringList 中删除另一个 QStringList 中包含的字符串

发布于 2024-12-17 21:46:13 字数 67 浏览 1 评论 0原文

我想知道是否有人知道 Qt 库方法可以采用两个 QStringList 并从第二个列表中删除一个列表中包含的所有字符串。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

土豪我们做朋友吧 2024-12-24 21:46:13

QList 中没有库函数,也没有 < a href="http://doc.qt.io/qt-5/qstringlist.html" rel="nofollow noreferrer">QStringList

但你可以编写自己的方法:

void remove(QStringList& list, const QStringList& toDelete){
  QStringListIterator i(toDelete);
  while(i.hasNext()){
    list.removeAll(i.next());
  }
}

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());
  }
}
不语却知心 2024-12-24 21:46:13

您可以使用QList::toSet()方法并执行一些my_set1.substract(my_set2),然后返回QSet::toList()代码>.
但这只是为了玩转转换代码。您最好使用给定的列表自己编写逻辑,它会更快并且不会涉及无用的内存分配(即使是临时的)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文