美文网首页
字符串与UTF8的转换

字符串与UTF8的转换

作者: 山野武夫 | 来源:发表于2021-03-13 22:52 被阅读0次

    iOS9之前

    字符串->UTF8

    NSString *string = [string stringByAddingPercentEscapesUsingEncoding:

    NSUTF8StringEncoding];

    UTF8->字符串

    NSString *string = [string stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    iOS9之后

    字符串->UTF8

    NSString *string = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

    UTF8->字符串

    NSString *string = [string stringByRemovingPercentEncoding];

    相关文章

      网友评论

          本文标题:字符串与UTF8的转换

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