Fill 2 arrays with the terms you'll find in each array, then make a loop on one array to see if the term is present in the other one. You can improve the loop by sorting them first and stopping the search earlier.
NSMutableArray *arrCommonWords =[[NSMutableArray alloc] init];
NSString *stringWithWOrds1;
NSArray *stringArray1 = [stringWithWOrds componentsSeparatedByString:@" "]; //Here put your sepqrator (I have put space)
NSString *stringWithWOrds2;
NSArray *stringArray2 = [stringWithWOrds componentsSeparatedByString:@" "]; //Here put your sepqrator (I have put space)
for(NSString *strTmp in stringArray1)
{
for(NSString *strTmp1 in stringArray2)
{
if([strTmp isEqualToString:strTmp1])
{
[arrCommonWords addObject:strTmp];
break;
}
}
}
This should help you.
NSMutableArray *arrCommonWords =[[NSMutableArray alloc] init];
NSString *stringWithWOrds1;
NSArray *stringArray1 = [stringWithWOrds componentsSeparatedByString:@" "]; //Here put your sepqrator (I have put space)
NSString *stringWithWOrds2;
NSArray *stringArray2 = [stringWithWOrds componentsSeparatedByString:@" "]; //Here put your sepqrator (I have put space)
for(NSString *strTmp in stringArray1)
{
for(NSString *strTmp1 in stringArray2)
{
if([strTmp isEqualToString:strTmp1])
{
[arrCommonWords addObject:strTmp];
break;
}
}
}
发布评论
评论(2)
用您将在每个数组中找到的术语填充 2 个数组,然后在一个数组上进行循环以查看该术语是否存在于另一个数组中。您可以通过首先对它们进行排序并提前停止搜索来改进循环。
Fill 2 arrays with the terms you'll find in each array, then make a loop on one array to see if the term is present in the other one. You can improve the loop by sorting them first and stopping the search earlier.
这应该对你有帮助。
This should help you.