作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 NSMutableAttributedString,我需要从中获取子字符串。我使用以下代码获取子字符串,
startIndex 和 endIndex 是两个长变量。
NSMutableAttributedString *currentString = (NSMutableAttributedString *)[attributtedString attributedSubstringFromRange:NSMakeRange(startIndex, endIndex)];
但如果指数走高则异常(exception)。字符串长度始终为 - 21212我可以在给定值时获得输出 (9048, 10958)但是在那之后,当我给出值 (10958, 12961) 时出现异常,
NSConcreteMutableAttributedString attributedSubstringFromRange:: Out of bounds
帮我解决这个问题,或者给我一个更好的方法来从 NSMutableAttributedString 中获取子字符串
提前致谢,
最佳答案
这不是 NSRange 的工作方式。它是 location
(对您来说是 startIndex)和 length
。因此,第二个从 10958 变为 10958 + 12961 = 23919,这是越界的。
关于iphone - attributedSubstringFromRange 越界问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6311922/
我有一个 NSMutableAttributedString,我需要从中获取子字符串。我使用以下代码获取子字符串, startIndex 和 endIndex 是两个长变量。 NSMutableAtt
我是一名优秀的程序员,十分优秀!