gpt4 book ai didi

iphone - attributedSubstringFromRange 越界问题

转载 作者:行者123 更新时间:2023-11-28 19:23:41 27 4
gpt4 key购买 nike

我有一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com