[英]NSRange giving nonsensical location
I'm experiencing this weird effect where calling location on rangeOfString is returning a very large value when it shouldn't... 我遇到这种奇怪的效果,在rangeOfString上调用location时它应该返回一个非常大的值,当它不应该...
my code looks like this: 我的代码看起来像这样:
NSRange range = [string rangeOfString:subString];
NSLog(@"range is %@", NSStringFromRange(range));
this logs out to range is {2147483647, 0}
这个注销
range is {2147483647, 0}
Can't figure out why exactly. 无法弄清楚为什么。
Some things that might be causing this: 可能导致此问题的一些事情:
any help greatly appreciated 任何帮助非常感谢
here is somethign that is striking me as weird: 这是一些让我感到奇怪的东西:
That just means that your substring is not present in your string, do the following to verify this: 这只是意味着您的子字符串不存在于您的字符串中,请执行以下操作来验证这一点:
NSRange range = [string rangeOfString:subString];
if (range.location == NSNotFound) {
NSLog(@"String not found");
} else {
NSLog(@"range is %@", NSStringFromRange(range));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.