美文网首页
NSString的编码和解码 UTF8编码

NSString的编码和解码 UTF8编码

作者: CodeLuck | 来源:发表于2017-09-19 14:39 被阅读0次

    //编码

    NSData *nsdata = [@"http://www.baidu.com" 

    dataUsingEncoding:NSUTF8StringEncoding];

    // Get NSString from NSData object in Base64

    NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];

    // Print the Base64 encoded string

    NSLog(@"Encoded: %@", base64Encoded);

    // 解码

    // NSData from the Base64 encoded str

    NSData *nsdataFromBase64String = [[NSData alloc]

    initWithBase64EncodedString:base64Encoded options:0];

    // Decoded NSString from the NSData

    NSString *base64Decoded = [[NSString alloc]

    initWithData:nsdataFromBase64String encoding:NSUTF8StringEncoding];

    NSLog(@"Decoded: %@", base64Decoded);

    iOS中对字符串进行UTF-8编码:输出str字符串的UTF-8格式

    [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    解码:把str字符串以UTF-8规则进行解码

    [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    相关文章

      网友评论

          本文标题:NSString的编码和解码 UTF8编码

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