0
如何做到這一點?我知道只是合併NSData不起作用。將RTF文件與Cocoa合併
如何做到這一點?我知道只是合併NSData不起作用。將RTF文件與Cocoa合併
與NSAttributedString玩應該工作,類似的代碼如下所示
這是合併許多RTF文件一起
- (void)mergeRTF:(NSURL*)rtf1 :(NSURL*)rtf2 :(NSURL*)merged {
NSMutableDictionary *options = [NSMutableDictionary dictionary];
[options setObject:[NSNumber numberWithUnsignedInteger:NSUTF8StringEncoding]
forKey:NSCharacterEncodingDocumentOption];
NSDictionary *docAttrs = nil;
NSError* error = nil;
NSAttributedString *rtfText1 = [[NSAttributedString alloc] initWithURL:rtf1
options:options
documentAttributes:&docAttrs
error:&error];
NSAttributedString *rtfText2 = [[NSAttributedString alloc] initWithURL:rtf2
options:options
documentAttributes:&docAttrs
error:&error];
NSMutableAttributedString* whole = [[NSMutableAttributedString alloc] initWithAttributedString:rtfText1];
[whole appendAttributedString:rtfText2];
NSData* data = [whole RTFFromRange:NSMakeRange(0, whole.length) documentAttributes:nil];
[data writeToURL:merged atomically:YES];
}
這工作非常快速和骯髒的方式,謝謝主席先生!聖誕節快樂!!! – Fatso
歡迎您:)新年快樂給你 – dafi