2011-06-10 2 views
1

J'ai un NSMutableAttributedString, je dois prendre de it.I substring utiliser le code suivant pour prendre substring,Hors limites problème attributedSubstringFromRange

startIndex et endIndex sont deux variables longues.

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

Mais il y a une exception si l'indice aller plus haut. La longueur de la chaîne est toujours - 21212 je peux obtenir une sortie quand je Les valeurs données (9048, 10958) Mais après quand j'ai donné des valeurs (10958, 12961), il y a une exception,

NSConcreteMutableAttributedString attributedSubstringFromRange:: Out of bounds 

aide moi résoudre ce problème, ou me donner une meilleure façon de prendre à partir d'un sous-chaîne NSMutableAttributedString

merci à l'avance,

Répondre

3

ce n'est pas comment fonctionne la NSRange. C'est location (startIndex pour vous) et length. Par conséquent, la seconde va de 10958 à 10958 + 12961 = 23919, ce qui est hors limites.