美文网首页
iOS base64和NSUTF8转码

iOS base64和NSUTF8转码

作者: 那小韩 | 来源:发表于2016-07-06 18:12 被阅读0次

    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];

    相关文章

      网友评论

          本文标题:iOS base64和NSUTF8转码

          本文链接:https://www.haomeiwen.com/subject/jjbkjttx.html