[英]How to find the Postion of all matching substrings in a QStringList
我正在寻找一种方法来查找QStringList
中所有匹配子字符串的单元格位置。
列表由一个 txt 文件填充,如下所示:
10:36:50,590/2002/1800
10:36:50,621/2002/1801
10:36:50,652/2002/1802
10:36:50,684/2002/1803
10:36:50,715/2002/1803
10:36:50,746/2002/1803
10:36:50,777/2002/1803/0/0/Target_Hit
10:36:50,809/2002/1802
10:36:50,840/2002/1802
10:36:50,871/2002/1802
10:36:50,965/2000/1831/0/0/Target_Hit
QStringList
的每个单元格都包含一行 txt 文件。 现在我想找到包含子字符串"Target_Hit"
的单元格的绝对命中数和位置。
我试图像这样找到它的数量: int number_of_hits = List.indexOf(QRegExp(".*\Target_Hit$));
但它返回-1
所以我猜QRegExp
不正确。
您不能为此使用 indexOf ,因为它只会返回一个索引,而且您似乎正在寻找多个索引。
我会逐行读取文件,检查每一行是否包含您要查找的内容,并记下这一点,实际上是这个伪代码:
initialise a counter to zero.
initialise a position list to an empty list.
read each line
check if the line contains the search string.
if it does: append the position into a list and increment the counter.
continue the next line.
然后,最后,你可以拥有你想要拥有的一切。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.