Original: C # issues needing attention in HTML translation
In the B/S program, we will use a little bit of HTML special symbol translation. such as: "&"-"&", "<"-"<", ">"-">", "" "-" "...
Symbol translation becomes code:
/// <summary> ///htmls the en code. /// </summary> /// <param name= "SHTML" >The HTML.</param> /// <returns></returns> Public Static stringHTMLEnCode (stringSHTML) { stringStemp =""; if(Shtml.length = =0) { return ""; } stemp= Shtml.replace ("<","<"); Stemp= Stemp.replace ("&","&"); Stemp= Stemp.replace (">",">"); Stemp= Stemp.replace ("'","& #39;"); Stemp= Stemp.replace (" "," "); Stemp= Stemp.replace ("\"","""); Stemp= Stemp.replace ("\ n","<br/>"); returnstemp; }
We use it when we need to convert it into HTML code:
/// <summary> ///htmls the de code. /// </summary> /// <param name= "SHTML" >The HTML.</param> /// <returns></returns> Public Static stringHtmlDecode (stringSHTML) { stringStemp =""; if(Shtml.length = =0) { return ""; } stemp= Shtml.replace ("<","<"); Stemp= Stemp.replace (">",">"); Stemp= Stemp.replace ("& #39;","'"); Stemp= Stemp.replace (" "," "); Stemp= Stemp.replace (""","\""); stemp = Stemp.replace ("& ", "& "); Stemp= Stemp.replace ("<br/>","\ n"); returnstemp; }
But we tend to overlook the most important point is that when we convert the translation into HTML, we need to pay attention to the order of transcoding, we have to "<", ">", "" "" "", "\" After the translation of the symbol of the final conversion "&" character, otherwise, the translated &am p; If followed by "nbsp;" Such consecutive characters will be converted to a space.
Do not accumulate kuibu, not even thousands of miles, no small stream, no to become Jianghai. Just accumulate, hope this discovery can also help you!