NSStrings - 基本术语提取

发布于 2024-11-26 19:16:11 字数 1431 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给妤﹃绝世温柔 2024-12-03 19:16:11

用您将在每个数组中找到的术语填充 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.

不必了 2024-12-03 19:16:11

这应该对你有帮助。

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;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文