我有奇怪的问题。以下子字符串代码崩溃
NSString *string4 = @"<p>some</p><img></img><p></p>end of the story":
[string4 substringWithRange:NSMakeRange(7, [string4 length] - 1)];
我假设范围在边界内,但它仍然崩溃。知道为什么会这样吗?以下是它显示的错误。
* Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString substringWithRange:]: Range or index out of bounds' * First throw call stack: (0x1c92012 0x10cfe7e 0x1c91deb 0x1c6aaa4 0x2bbc 0xf51c7 0xf5232 0x443d5 0x4476f 0x44905 0x4d917 0x27c5 0x11157 0x11747 0x1294b 0x23cb5 0x24beb 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1217a 0x13ffc 0x24fd 0x2425)抛出异常(将终止调用)