-1

我有两个 NSStrings,我想找到两者共同的词作为术语提取的基本形式......

任何想法如何去做?

罗伊

4

2 回答 2

2

用您在每个数组中找到的术语填充 2 个数组,然后在一个数组上循环以查看该术语是否存在于另一个数组中。您可以通过先对它们进行排序并提前停止搜索来改进循环。

于 2011-07-27T08:44:56.003 回答
2

这应该可以帮助你。

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;
        }
    }
}
于 2011-07-27T08:48:22.323 回答