5

最後の50 行ほどNSAttributedStringしか取得できないように分割する簡単な方法はありますか?

NSMutableAttributedString *resultString = [receiveView.attributedText mutableCopy];
[resultString appendAttributedString:[ansiEscapeHelper attributedStringWithANSIEscapedString:message]];
if ([[resultString.string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] count]>50) {
    //resultString = [resultString getLastFiftyLines];
}
4

2 に答える 2

3

NSAttributedString を分割して、最後の 50 行ほどしか取得しない簡単な方法はありますか?

いいえ。 をリクエストして、関心のある範囲を決定し、次のような API を使用してソースから派生しstringた新しい表現を作成する必要があります。NSAttributedString- [NSAttributedString attributedSubstringFromRange:]

- (NSAttributedString *)lastFiftyLinesOfAttributedString:(NSAttributedString *)pInput
{
  NSString * string = pInput.string;
  NSRange rangeOfInterest = ...determine the last 50 lines in "string"...;
 return [pInput attributedSubstringFromRange:rangeOfInterest];
}
于 2013-07-01T19:40:58.133 に答える