To meet certain special needs, characters must be transcoded according to rules to facilitate transmission, presentation, and other operations. Let's take a look at the following transcoding to find out its usefulness. 1. String transcoding completes Conversion Based on the original encoding format and the target encoding format. However, garbled characters may occur. The previous chapter has already been introduced. Code: copy the code /// <summary> /// string encoding conversion /// </summary> /// <param name = "srcEncoding"> original encoding </param> // /<param name = "dstEncoding"> Target encoding </param> // <param name = "srcBytes"> original string </param> // <returns> string </returns> public static string TransferEncoding (Encoding srcEncoding, encoding dstEncoding, string srcStr) {byte [] srcBytes = srcEncoding. getBytes (srcStr); byte [] bytes = Encoding. convert (srcEncoding, dstEnc Oding, srcBytes); return dstEncoding. GetString (bytes);} copy the code test case: input = "welcome to the transcoding world! "; Result = Transfer. TransferEncoding (Encoding. Default, Encoding. UTF8, input); // welcome to the transcoding world! Console. writeLine ("TransferEncoding result: {0}", result); result = Transfer. transferEncoding (Encoding. UTF8, Encoding. default, result); Console. writeLine ("TransferEncoding anti-transcoding result: {0}", result); // welcome to the transcoding world! 2. Html transcoding key points: characters <and> are encoded as & lt; and & gt when they are embedded into text blocks. If blank and punctuation characters are transmitted in the HTTP stream, they may be incorrectly interpreted at the receiving end. HTML encoding converts a character that is not allowed in HTML to an equivalent entity. HTML Decoding reverses this encoding process. For example, for HTTP transmission, characters <and> are encoded as & lt; and & gt; when embedded in a text block ;. To encode or decode values other than Web applications, use the WebUtility class. Transcoding: copy the code /// <summary> /// html transcoding /// </summary> /// <param name = "html"> </param> /// <returns> </returns> public static string HtmlEncode (string html) {return HttpUtility. htmlEncode (html); // System. net. webUtility. htmlEncode (html);} duplicate code decoding: copy the code /// <summary> /// html Decoding /// </summary> /// <param name = "html"> </param> /// <returns> </returns> public static string HtmlDecode (string html) {return HttpUt Ility. htmlDecode (html); // System. net. webUtility. htmlDecode (html);} copy the code test case: copy the code // HtmlEncode test result = string. empty; input = "