有没有一种情况,当 range.location > targetString.length, range.length !=0

Is there a situation that when range.location > targetString.length, range.length !=0

  1. 有没有可能当range.location > targetString.length然后range.length !=0
  2. 判断范围变量是否存在的最佳方法是什么?

无效的 NSRangelocation 成员设置为 NSNotFound(即 NSIntegerMax),因此:

  1. 是的,当范围无效时,但是在那种情况下 length 成员应该被忽略。
  2. 如果 "exists" 你的意思是 "valid",就是 location != NSNotFound.