Qt5 中字符串搜索的最佳容器
Best container for string search in Qt5
在我的项目中,我需要确定字符串列表中字符串的出现次数。不允许列表中的重复项,并且顺序无关紧要。
请帮我为字符串搜索选择最好的Qt容器。
如果你想要一个字符串列表,Qt提供了QStringList类。
添加所有字符串后,可以调用 removeDuplicates 函数来满足无重复项的要求。
若要搜索字符串,请调用 filter 函数,该函数返回包含字符串的字符串列表或传递给函数的正则表达式。
下面是一个改编自Qt文档的示例:
// create the list and add strings
QStringList list;
list << "Bill Murray" << "John Doe" << "Bill Clinton";
// Oops...added the same name
list << "John Doe";
// remove any duplicates
list.removeDuplicates();
// search for any strings containing "Bill"
QStringList result;
result = list.filter("Bill");
结果是一个包含"Bill Murray"和"Bill Clinton"的QStringList。
如果您只想知道字符串是否在列表中,请使用 包含函数
bool bFound = list.contains("Bill Murray");
找到将返回 true。
相关文章:
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 有根的二进制搜索树.保留与其父级的链接
- 从整数向量向量搜索整数向量的最佳算法
- 比较/搜索数组中多个整数的最佳解决方案
- 在unordered_map中搜索的最佳实践
- 从基于矢量的二叉搜索树中删除节点的最佳方法
- 哪种数据结构是在一个向量中搜索和计数对象对的最佳数据结构
- 一半填充二进制搜索树进行测试的最佳方法
- 二进制搜索树最佳拟合算法:输出不正确
- 搜索子集、算法(最佳或启发式)
- Qt5 中字符串搜索的最佳容器
- 在C++中存储和搜索数字的最佳方式
- 使用std::vector将数组的最佳匹配搜索到矩阵中
- 搜索std::集的最佳方式
- 如何以最佳、最简单的方式在文件中搜索
- 在N个未排序的数字中搜索给定值的最佳方法
- 在C++中存储和搜索短语的最佳数据结构
- 使用整数列表文档进行全文搜索的最佳方法
- 基于Korf 1992的c++实现递归最佳优先搜索的问题
- 在C++中实现 2D 间隔搜索的最佳方法是什么?