问题
I have a NSMutableAttributedString, I need to take substring from it.I use the following code to take substring,
startIndex and endIndex are two long variables.
NSMutableAttributedString *currentString = (NSMutableAttributedString *)[attributtedString attributedSubstringFromRange:NSMakeRange(startIndex, endIndex)];
But there is an exception if index go higher. The String Length is always - 21212 I can get output when I given values (9048, 10958) But after that when I gave values (10958, 12961) there is an Exception,
NSConcreteMutableAttributedString attributedSubstringFromRange:: Out of bounds
help me in solving this issue, or give me a better way to take substring from a NSMutableAttributedString
thanks in advance,
回答1:
This isn't how NSRange works. It is location
(startIndex for you) and length
. Hence the second goes from 10958 to 10958 + 12961 = 23919, which is out of bounds.
来源:https://stackoverflow.com/questions/6311922/out-of-bounds-problem-with-attributedsubstringfromrange