开发者

Is there a way for NSString to display HTML character codes?

开发者 https://www.devze.com 2023-02-24 09:50 出处:网络
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 GTMN

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 &ltHTML-Tag&gt";

     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

0

精彩评论

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