Method One:
The code below, if there is a better way to post the trouble, this method is decoded by WebView
UIWebView *web = [[UIWebView alloc] init];
NSString *TSW = @ "%E4%B8%AD%E5%9B%BD";
NSString *SC = [NSString stringwithformat:@ "decodeuricomponent ('%@ ')", TSW];
NSString *st = [Web STRINGBYEVALUATINGJAVASCRIPTFROMSTRING:SC];
NSLog (ST);
[Web release];
Method Two:
Test a bit, done, with nsstring of the Stringbyreplacingpercentescapesusingencoding method on it, can be like this:
nsstring* Strafterdecodebyutf8anduri = [@ "%E4%B8%AD%E5%9B%BD" stringbyreplacingpercentescapesusingencoding: Nsutf8stringencoding];
NSLog (@ "strafterdecodebyutf8anduri=%@", Strafterdecodebyutf8anduri);
The nature of the problem, first of all, this paragraph is utf-8 encoding, and then the URL Encode, so when decoding, the first URL Decode, and then utf-8 decoding can
What is URL encode see http://www.stringfunction.com/url-decode.html
So
The Stringbyreplacingpercentescapesusingencoding method is used for URL decode
Then the parameter nsutf8stringencoding is specified UTF-8 encoding can be
=================================
The implementation of http://www.cocoachina.com/bbs/read.php?tid-16787.html has also been analyzed as follows:
This approach is explained in principle.
Code definition, see C below)
A:There is three or four options for making Unicode fit to an 8-bit format.
A) Use UTF-8. This preserves is ASCII, but not Latin-1, because the characters >127 is different from Latin-1. UTF-8 uses the bytes in the ASCII is only for ASCII characters. Therefore, it works well in any environment where ASCII characters has a significance as syntax characters, e.g. file Nam e syntaxes, markup languages, etc., but where the-all and characters may use arbitrary bytes.
Example: "Latin Small letter S with Acute" (015B) would is encoded as, BYTES:C5 9B.
b) Use Java or C style escapes, of the form/uxxxxx or/xxxxxx. This format was not a standard for text files, but well defined in the framework of the languages in question, primarily for source files.
Example:the Polish word ' wyj?cie ' with character ' Latin Small letter S with Acute ' (015B) in the middle (? is one charact ER) would look like: "Wyj/u015bcie".
c) Use the & #xXXXX; or & #DDDDD; Numeric character escapes as in HTML or XML. Again, these is not standard for plain text files, but well defined within the framework of these markup languages.
Example: "Wyj?cie" would look like "wyj& #x015B; CIE"
d) Use SCSU. This format compresses Unicode to 8-bit format, preserving most of ASCII, but using some of the control codes as command s for the decoder. However, while ASCII text would look like ASCII text after being encoded in SCSU, other characters could occasionally be Enco Ded with the same byte values, making SCSU unsuitable for 8-bit channels this blindly interpret any of the bytes as ASCII Characters.
Example: "<SC2> wyjûcie" where <SC2> indicates the byte 0x12 and "Û" corresponds to byte 0xDB.
As described in C, this is a "nonstandard" but widely used practice, said the cottage code is also line:-)
So the coding process is
String--Unicode encoding & #xXXXX; or & #DDDDD;
The decoding process can, in turn,
Note: Because this encoding is "cottage" is not "standard" encoding, so the iphone SDK is not supported (not to the above Utf-8 encoding), can only be done by themselves (nor is it difficult, see DBOYLX implementation)
Convert UTF8 encoding to Chinese-nsstring method