gpt4 book ai didi

ios - 从 NSAttributedString 中提取最后 50 行

转载 作者:可可西里 更新时间:2023-11-01 04:39:46 24 4
gpt4 key购买 nike

是否有一种简单的方法来拆分 NSAttributedString 以便我只得到最后 50 行左右?

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

最佳答案

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

没有。您将必须请求 string 并确定您感兴趣的范围,然后使用 - [ NSAttributedString attributedSubstringFromRange:]:

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

关于ios - 从 NSAttributedString 中提取最后 50 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17412024/

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