计数列表框重复项 [英] Counting List Box Duplicate Items
本文介绍了计数列表框重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好.
我有两个列表框.其中之一充满了文件名及其目录.
我想在第一个列表框中计算所有重复的文件名,然后在第二个列表框中放入文件名和重复数.
点赞:0.TXT(6)
该程序: http://img178.imageshack.us/img178/2160/82415716.png [ ^ ]
我使用VC ++,所以请给我C ++代码,因为我还是个初学者. :((
提前致谢. :-O
Hello all.
I have two list boxes. One of them is filled with file names and their directories.
I want to count all duplicate file names in the first list box and put the file name and the number of duplication in the second list box.
like: 0.TXT (6)
the program:http://img178.imageshack.us/img178/2160/82415716.png[^]
I use VC++, so please give me C++ code for I''m still a beginner. :((
Thanks in advance. :-O
推荐答案
即使在vb.net中也检查该链接,但是您可以理解它的算法:
链接 [
check that link even it is in vb.net but you can understand the algorithem of it :
link[^]
the trick is to create 2 nested loops :
while(i<listbox.count){>
for(k<listbos.count){>
// then check if(listbox[i]==listbox[k]){
then add this item to the new list ...
}}
regards...
非常感谢您的回答,但我真的无法理解其中的许多表达方式.
我用谷歌搜索,但发现的只是VB代码.
关于您上面提供的想法,我尝试了一下,但它给了我一个超出范围的异常.
这是我到目前为止所做的:
thanks a lot for the answer but I really couldn''t understand many of it''s expressions.
I googled it but all I found was VB code.
and about the idea you provided above, I tried it but it gives me an out of range exception.
here is what I did so far:
int L = listBox1->Items->Count::get();
int i = 0;
while(i<l)>
{
i++;
for(int k=0; k<l;>
{
if(listBox1->Items[i]==listBox1->Items[k])
{
listBox2->Items->Add(listBox1->Items[i]);
}
}
}
抱歉,如果我错了!
Sorry if I were wrong!
是的,它肯定会超出范围,我只是给出了一个想法而没有给出完整的逻辑...
诀窍是从我们到达最后一次的第二个循环开始...
这是逻辑:
对于(i = 0; i< count; i ++){>
for(j = i + 1; j< count-i; j ++){>
然后做任何你想做的事}
}
问候...
yes sure it will give out of range I just gave an idea without giving the fulllogic ...
the trick is to start in the second loop where we have reached the last time ...
here is the logic :
for ( i=0;i<count;i++){>
for( j=i+1;j<count-i;j++){>
then do what ever you want }
}
regards...
这篇关于计数列表框重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文