Код перекодировки строки в UTF8 и обратно
//Encode NSString to UTF8
+ (NSString *)encode2UTF8:(NSString *)originalStr
{
NSString *encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)originalStr,NULL,NULL,kCFStringEncodingUTF8));
return encodedString;
}
//Decode UTF8 NSString
+ (NSString *)decodeFromUTF8:(NSString *)utf8Str
{
return [utf8Str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
//Encode NSString to UTF8
+ (NSString *)encode2UTF8:(NSString *)originalStr
{
NSString *encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)originalStr,NULL,NULL,kCFStringEncodingUTF8));
return encodedString;
}
//Decode UTF8 NSString
+ (NSString *)decodeFromUTF8:(NSString *)utf8Str
{
return [utf8Str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
0 коментарі:
Отправить комментарий