开发者

Converting rtf data in an NSData object to a NSString object

I'm working on iOS and I want to read rtf data thats in an NSData (actually its an attribute in a core data entity). I'm using the following code:

NSString *temp = [NSString str开发者_StackOverflow中文版ingWithUTF8String:[self.task.notes bytes]];

NSLog(@"%@ %i", temp, [temp length]);

The console yields the message "rtfd 4". But I'm looking for the rtfd raw data. Thank you for your help, Jose.


this may or not be of any help

// USAGE NSLog(@"%@",[Utilities dataToString:data delimiter:@"|"]);
+(NSString*)dataToString:(NSData*)inData delimiter:(NSString*)delimiter {
    if ([inData length] == 0) {
        return @"";
    }
    if (delimiter == nil) {
        delimiter = @"";
    }
    const unsigned char * p= (const unsigned char *) [inData bytes];
    NSMutableString* outString= [[NSMutableString alloc]initWithCapacity:[inData length]*3];
    for (int i=0; i< [inData length]; i++) {
        [outString appendFormat:@"%02x",p[i]];
        [outString appendString:delimiter];
    }
    [outString autorelease];
    return outString;
}


If you want the raw string of a RTFD data stream, then you use this code in Swift:

let raw = String(data: data, encoding: .ascii)

In case you have a RTF data stream, use this code:

let raw = String(data: data, encoding: .utf8)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜