NSStrings - 基本术语提取

时间:2011-07-27 08:40:52

标签: iphone nsstring text-extraction term

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

任何想法如何解决这个问题?

罗伊

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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;
        }
    }
}