In the use of network address, it is generally necessary to first encode the URL into the UTF8 format of the encoding, or in use may report the URL does not exist errors, then need to convert
Here is the conversion function:
NSString *urlstring= [NSString stringwithformat:@ "http://www.baidu.com];
NSString * encodedstring = (NSString *) cfurlcreatestringbyaddingpercentescapes (Kcfallocatordefault, (CFSTRINGREF) URLString, NULL, NULL, KCFSTRINGENCODINGUTF8);
Nsurl *url =[nsurl urlwithstring:encodedstring];
Or use the following method:
NSString UTF8STR = @ "testing";
NSString *unicodestr = [NSString stringwithcstring:[utf8str utf8string] encoding:nsunicodestringencoding];
Sometimes get the URL of the Chinese characters are garbled, the Web content is garbled, need to be transcoded to correctly identify NSString, you can use the following method:
Solve garbled problems ()
NSString *transstring = [NSString stringwithstring:[string stringbyreplacingpercentescapesusingencoding: Nsutf8stringencoding]];