- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个列表。两者包含相同的值:
QStringList filePaths;
filePaths.append("C:/backup");
filePaths.append("C:/download/file1");
filePaths.append("D:");
filePaths.append("C:/program");
filePaths.append("C:/download");
QStringList refinedPaths;
int size = filePaths.size();
for(int i = 0; i < size; i++)
{
refinedPaths.append(filePaths.at(i));
}
for(int i = 0; i < size; i++)
{
QString str1 = filePaths.at(i);
for(int j = 0; j < size; j++)
{
QString str2 = filePaths.at(j);
if(str2 == str1)
{
continue;
}
if(str2.startsWith(str1))
{
refinedPaths.removeAll(str2);
}
}
}
我期望发生的是: * 遍历列表中的字符串,比较列表中的每个项目。 * 如果string1以string2开头(因此string2是string1的父目录) * 从“精炼”字符串列表中删除该字符串。
但是,发生的事情是 if(str2.startsWith(str1))
每次都返回 true,而 refinedPaths.removeAll(str2);
却没有删除列表中的任何字符串。
有什么想法吗?
最佳答案
下面的片段根据需要合理化了列表。
foreach (const QString& path, filePaths)
{
foreach (const QString& other, filePaths)
{
if (other != path && other.startsWith(path))
filePaths.removeOne (other);
}
}
关于c++ - QString::startWith() 和 QStringList::removeAll() 未按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7334909/
我不确定 groovy 中的 removeAll 是如何工作的,但我希望它会返回 [40289454470ea94601470ea977d00018] def list = ['40289454470
我在使用 Netbeans 制作的 Java 应用程序中遇到了奇怪的问题。这是一款内存卡游戏。主类是一个 JFrame,它保存相同大小的面板。面板通过网格布局进行分割,每个单元格都包含一张卡片,另一个
List vAllBatchList = getAllBatchCollection().toList(); //Has 700k records List vKeepableBatchCollect
我编写了一个通用的 Partition 类(分区是将一个集合划分为不相交的子集,称为部分)。在内部这是一个 Map和一个 Map> ,其中整数是零件的标签。例如partition.getLabel(T
我有两个自创建类对象的数组列表。比较后,我从两者中删除了公共(public)对象,并准备了获取公共(public)元素的方法。找到公共(public)元素后,我通过调用 removeAll() 方法删
我想要编写一段代码,它接受一个列表列表,将其拆分为 9 个子列表,并从每个子列表中的所有列表中删除数字。但是,当我的代码运行时,它会从所有列表中删除数字,而不仅仅是从原始列表中获取的部分 for (i
我是 Linq 的新手。根据我的理解,LINQ 应该只用于查询而不用于修改集合或数据库等。 如果是这样,微软为什么要提供 RemoveAll() 扩展? 据我所知,RemoveAll() 修改集合。
有人可以解释为什么以下内容无法按我的预期工作吗? 按下“应该”按钮会导致显示仅包含(空的)JScrollPane,即输入字段和按钮应该消失。但是,它们会一直保留到调整组件大小为止... public
我有一个超过 400 行的列表。每行看起来都类似于:example-example123 我想删除“-”之后的所有内容,这样我只剩下开头部分:example123任何帮助将不胜感激。 最佳答案 像这样
我有两个 for 循环来从列表中删除项目。我正在为这些循环寻找等效的 LINQ 语句 for (Int32 i = points.Count - 1; i >= 0; i--) { for (
我有一个页面,将 View 模型绑定(bind)到 jQuery UI 对话框内的 HTML 表。 当用户关闭对话框时,我想删除 viewmodel observableArray 中绑定(bind)
myGenericList.RemoveAll(x => (x.StudentName == "bad student")); 效果很好,但绑定(bind)列表没有此方法。如何为绑定(bind)列表创
我使用数组列表来查找两个字符串(即 str2 和 str3)之间的差异。当我使用下面的代码时,它工作正常并返回预期的输出。但当我更换时 str2 = #19, 6th cross, 7th main
我有一个小问题,数组列表中的元素没有被删除。这是一个数组列表。这是我的代码: package net.lucrecious.armorconstruct.helpers; import java.ut
我有成员类的简单ArrayList: ArrayList mGroupMembers = new ArrayList<>(); ArrayList mFriends = new ArrayList<>
我预计结果如下,但实际上没有。尽管当我尝试使用字符串而不是项目对象时它起作用了。我想知道为什么会这样以及如何编码以获得预期结果。谢谢。 EXPECTED -----------------------
我有以下代码: ActionListener listenerComboVehicle = new ActionListener() { @Override public void a
(我已经根据“removeall where”或“removeall two argument predicate”的关键字做了尽可能多的搜索,但运气不佳,所以这里开始) 问题是我有一个对象列表(Wa
在通过 NHibernate 检索集合时,我遇到了无法使用 .RemoveAll 的问题。 我有一个名为 Order 的实体,我通过 NHibernate 保留它。 Order 有很多 OrderIt
我有两个列表,我们称它们为列表 A 和列表 B。这两个列表都包含名称并且没有重复项(它们是唯一值)。列表 B 中的每个名称都可以在列表 A 中找到。我想找出列表 B 中缺少哪些名称,以便将这些缺少的名
我是一名优秀的程序员,十分优秀!