Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract the last 50 lines from an NSAttributedString

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];
}
like image 476
David Karlsson Avatar asked Jul 01 '13 19:07

David Karlsson


1 Answers

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];
}
like image 181
justin Avatar answered Sep 29 '22 07:09

justin