越界boundsubstringFromRange的问题
我有一个NSMutableAttributedString,我需要从它的子string。我使用下面的代码来获取子string,
startIndex和endIndex是两个长variables。
NSMutableAttributedString *currentString = (NSMutableAttributedString *)[attributtedString attributedSubstringFromRange:NSMakeRange(startIndex, endIndex)];
但是,如果指数走高,则有一个例外。 string长度总是 – 21212我可以得到输出时,我给定的值(9048,10958)但之后,当我给值(10958,12961)有一个例外,
NSConcreteMutableAttributedString attributedSubstringFromRange:: Out of bounds
帮助我解决这个问题,或者给我一个更好的方法从NSMutableAttributedString中获取子string
提前致谢,
这不是NSRange的工作原理。 它是location
(startIndex为你)和length
。 因此,第二个从10958到10958 + 12961 = 23919,这是超出界限的。