【问题标题】:Out of bounds Problem with attributedSubstringFromRange属性的SubstringFromRange 越界问题
【发布时间】:2011-06-10 20:49:48
【问题描述】:

我有一个 NSMutableAttributedString,我需要从中获取子字符串。我使用以下代码获取子字符串,

startIndex 和 endIndex 是两个长变量。

NSMutableAttributedString *currentString = (NSMutableAttributedString *)[attributtedString attributedSubstringFromRange:NSMakeRange(startIndex, endIndex)];

但如果索引更高,则有一个例外。 字符串长度始终为 - 21212 当我给定值时,我可以得到输出(9048、10958) 但是在那之后,当我给出值 (10958, 12961) 时,就会出现异常,

NSConcreteMutableAttributedString attributedSubstringFromRange:: Out of bounds

帮我解决这个问题,或者给我一个更好的方法来从 NSMutableAttributedString 中获取子字符串

提前致谢,

【问题讨论】:

    标签: iphone ios ipad indexoutofboundsexception


    【解决方案1】:

    这不是 NSRange 的工作方式。它是location(你的startIndex)和length。因此,第二个从 10958 变为 10958 + 12961 = 23919,超出范围。

    【讨论】:

      猜你喜欢
      • 2018-06-07
      • 2012-11-04
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多