This is actually a lot of things to see, especially when using JSON more,
In fact, it's very simple. The main use of the ToString ("x") method
Just look at the code.
stringstr ="Hello, I'm zhe."; stringOUTSTR =""; if(!string. IsNullOrEmpty (str)) { for(inti =0; I < Str. Length; i++) { //converts a Chinese character to a 10-based integer and then to a 16-Unicode characterOutstr + ="\\u"+ ((int) str). ToString ("x"); } }
Here's how to turn Unicode data into Chinese
Like the following data, for example.
\u8c01\u80fd\u591f\u7ed9\u6211\u98ce\u9669\u6295\u8d44\u54e6!\u6211\u60f3\u501f\u5341\u4e07\u529e\u4e00\u4e2a\ U517b\u6b96\u5382\u3002\u6211\u53ef\u662f\u6709\u5bb6\u5ead\u62c5\u4fdd\u7684\u54e6!#\u4e0a\u7f51\u7231\u901b\ U4ec0\u4e48
Here is mainly the use of the Parse method
Let's see how it's achieved.
Private voidForm1_Load (Objectsender, EventArgs e) { stringstr =@"\u8c01\u80fd\u591f"; STR=unicontostring (str); } /// <summary> ///Convert Unicon string to Chinese character string/// </summary> /// <param name= "str" >Unicon String</param> /// <returns>Kanji String</returns> Public stringUnicontostring (stringstr) { stringOUTSTR =""; if(!string. IsNullOrEmpty (str)) {string[] strlist = str. Replace ("\\",""). Split ('u'); Try { for(inti =1; I < Strlist. Length; i++) { //converts a Unicode character to a 10-in integer and then to char Chinese charactersOutstr + = (Char)int. Parse (Strlist, System.Globalization.NumberStyles.HexNumber); } } Catch(FormatException ex) {outstr=Ex. Message; } } returnoutstr; }
in the edit box, fill in the \u7b2c01\u96c6 string temp = txturl.text; Console.WriteLine (uri.unescapedatastring ("\u7b2c01\u96c6")); Only this can decode Console.WriteLine (uri.unescapedatastring (temp)); Console.WriteLine (Httputility.urldecode (temp, Encoding.UTF8));
C # Chinese and Unicode character conversion methods