查找 NSArray 中重复项的索引
我有一个数组,就像
[chapter,indent,left,indent,nonindent,chapter,chapter,indent,indent,left];
我需要查找重复项和非重复元素的索引。 如何做到这一点......给出一些示例代码或逻辑...... 提前感谢
我使用 Objective C...
NSArray *myWords = [string componentsSeparatedByString:@"class=\""];
int count_var=[myWords count];
tmp1=@"";
for(int i=1;i<count_var;i++)
{
str=[NSString stringWithFormat:@"\n%@",[myWords objectAtIndex:i]];
class=[str componentsSeparatedByString:@"\""];
NSString *tmp=[NSString stringWithFormat:@"%@",[class objectAtIndex:0]];
tmp1=[[NSString stringWithFormat:@"%@",tmp1] stringByAppendingString:[NSString stringWithFormat:@"%@",tmp]];
}
t1.editable=NO;
t1.text=tmp1;
NSArray *tempo=[[NSArray alloc]init];
tempo=[tmp1 componentsSeparatedByString:@"\n"];
tempCount=[tempo count];
这是我的示例代码...其中数组速度包含该数组中的所有对象,我想获取重复字符串的索引≥。
i have an array like
[chapter,indent,left,indent,nonindent,chapter,chapter,indent,indent,left];
i need to find indexes of duplicates and also non duplicate elements .
how to do this...........give some sample code or logic......
thanks in advance
iam using objective c.....
NSArray *myWords = [string componentsSeparatedByString:@"class=\""];
int count_var=[myWords count];
tmp1=@"";
for(int i=1;i<count_var;i++)
{
str=[NSString stringWithFormat:@"\n%@",[myWords objectAtIndex:i]];
class=[str componentsSeparatedByString:@"\""];
NSString *tmp=[NSString stringWithFormat:@"%@",[class objectAtIndex:0]];
tmp1=[[NSString stringWithFormat:@"%@",tmp1] stringByAppendingString:[NSString stringWithFormat:@"%@",tmp]];
}
t1.editable=NO;
t1.text=tmp1;
NSArray *tempo=[[NSArray alloc]init];
tempo=[tmp1 componentsSeparatedByString:@"\n"];
tempCount=[tempo count];
this is my sample code...in this the array tempo contains all objects from that array i want to get index of duplicate strings≥.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以构建一个将对象映射到索引集的字典。对于每个索引集,
-count
为1
表示没有重复项,> 1
表示存在重复项。You could build a dictionary mapping the objects to index sets. For every index set, a
-count
of1
means no duplicates,> 1
means there are duplicates.