I have an NSString tha开发者_开发问答t has the following value:
"What#39;s up fellas!"
Is there a simple way to turn HTML char codes like #39;
(equivalent to ') into an apostrophe etc?
check GTMNSString+HTML.h out :) It's a part of the Google Toolbox, an extension for iOS development. taken from this question
Try this one, it works:
#import "NSString+HTML.h"
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *r = @"This is a '\'";
NSString *s = @"This is a <HTML-Tag>";
NSString *encodedstring = [r kv_encodeHTMLCharacterEntities];
NSString *decodedstring = [s kv_decodeHTMLCharacterEntities];
}
NSString has an UTF8 encode-decode function:
- (id)initWithUTF8String:(const char *)bytes
+ (id)stringWithUTF8String:(const char *)bytes
- (const char *)UTF8String
See the Class Reference here
精彩评论