UTF-8 ->GBK

时间:2023-12-16 20:34:14

/**

* GBK->UTF8

*/

//方法一 旧方法

//NSString *encode1 = [@"%E6%88%91" stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

//NSLog(@"--encode1->%@<------", encode1);

//方法二   新方法

//NSLog(@"--encode2->%@<------", [@"%E6%88%91" stringByRemovingPercentEncoding]);

/**

*  UTF-8 ->GBK

*/

//方法一 旧方法

//NSString *decode1 = [@"我" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

//NSLog(@"--decode1-->%@<-----", decode1);

//方法二 新方法

//NSLog(@"--decode1-->%@<-----",  [@"我" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]);