开发者

Out of bounds Problem with attributedSubstringFromRange

开发者 https://www.devze.com 2023-03-12 16:17 出处:网络
I have a NSMutableAttributedString, I need to take substring from it.I use the following code to take substring,

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

h开发者_如何学Celp me in solving this issue, or give me a better way to take substring from a NSMutableAttributedString

thanks in advance,


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消