gpt4 book ai didi

Objective-C 提取 rangeOfString : 返回的范围的索引

转载 作者:行者123 更新时间:2023-12-01 08:01:56 25 4
gpt4 key购买 nike

如何从

中提取 NSUInteger 索引
NSRange range = [string rangeOfString: substring]

所以我可以在[array objectAtIndex:index]中写这个索引?

最佳答案

// make sure that the substring was actually found:
NSRange result = [string rangeOfString:substring];

if (result.location != NSNotFound)
{
// make sure that the index exists in the array
if (result.location < [array count])
{
id someObj = [array objectAtIndex:result.location];
// do something cool with someObj here
}
}

关于Objective-C 提取 rangeOfString : 返回的范围的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7922996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com