Frage

Is there a simple way to split a NSAttributedString so I get only the last 50 or so lines?

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

Lösung

is there a simple way to split a NSAttributedString so i get only the last 50 or so lines?

No. You will have to request the string and determine the range you are interested in, then create a new NSAttributedString representation derived from the source using an API such as - [NSAttributedString attributedSubstringFromRange:]:

- (NSAttributedString *)lastFiftyLinesOfAttributedString:(NSAttributedString *)pInput
{
  NSString * string = pInput.string;
  NSRange rangeOfInterest = ...determine the last 50 lines in "string"...;
 return [pInput attributedSubstringFromRange:rangeOfInterest];
}

Andere Tipps

You can use substring method of AttributedString:

if ([resultString length]>50) {
  resultString = [resultString attributedSubstringFromRange:NSMakeRange(0, 50)];
}

NSMakeRange - 0 tells us where to start and 50 is length of substring

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top