/ Published in: Objective C
Convert UTF-8 NSData to NSString without failing if UTF-8 is invalid. Instead, replace invalid characters with the replacement character (�). This requires some Omni frameworks. Use this as a replacement for NSString's initWithData:encoding: method.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// http://www.omnigroup.com/ftp/pub/software/Source/MacOSX/Frameworks/ // Link with {OWF, OmniFoundation, OmniBase, OmniNetworking} // http://forums.omnigroup.com/showthread.php?t=1867 #import <OWF/OWDataStream.h> #import <OWF/OWDataStreamCharacterCursor.h> { OWDataStream *dataStream = [[[OWDataStream alloc] initWithLength:[data length]] autorelease]; [dataStream writeData:data]; return OFMostlyApplyDeferredEncoding([[[[OWDataStreamCharacterCursor alloc] initForDataCursor:[dataStream newCursor] encoding:OFDeferredASCIISupersetStringEncoding] autorelease] readString], kCFStringEncodingUTF8); }