NSUTF8的编码:
NSString *tvtext=[tv_idea.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//编码
NSUTF8的解码:
NSString *str_con = [dic[@"comment_content"] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Base64编码
+ (NSString *)base64StringFromText:(NSString *)text {
NSData *data = [text dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64String = [data base64EncodedStringWithOptions:0];
return base64String;
}
base64解码:
+ (NSString *)textFromBase64String:(NSString *)base64 {
NSData *data = [[NSData alloc]initWithBase64EncodedString:base64 options:0];
NSString *text = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
return text;
}
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *stringBase64 = [data base64Encoding];
NSData *data = [[NSDataalloc] initWithBase64EncodedString:base64options:0];
NSString *text = [[NSStringalloc] initWithData:dataencoding:NSUTF8StringEncoding];
网友评论