iOS Unicode和漢字互轉

iOS9以前ios

//unicode轉中文
NSString* strA = [@"%E4%B8%AD%E5%9B%BD"stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//中文轉unicode
NSString *strB = [@"中國"stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

ios9以後url

NSString *urlStr = @"http://img5.imgtn.bdimg.com/it/u=3572074785,265614668&fm=21&gp=0.jpg";
    //轉成unicode
    urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    //unicode
    urlStr = [urlStr stringByRemovingPercentEncoding];
相關文章
相關標籤/搜索