asp.net of string and HTML decimal coding to implement code _ practical skills

Source: Internet
Author: User

asp.net the string to & #区码位编码, or & #区码位编码字符串转为对应的字符串内容.

& #数字; This encoding is actually to convert a single character to the corresponding area code bit (number), and then the area code bit prefix plus "&#", suffix plus ";" , the browser automatically resolves to the corresponding character for this encoded string.

asp.net string and & #编码转换源代码和测试代码如下:

Using System;
Using System.Text.RegularExpressions; Public partial class Purchase_property:System.Web.UI.Page {///<summary>///asp.net converts a string into a 16-code-bit & #编码/// </summary>///<param name= "S" > the string to be encoded in the 16-bit code </param>///<returns> encoded 16 code bit & #字符串 </returns> public string Stringtounicodecodebit (string s) {if (string). IsNullOrEmpty (s) | |
  S.trim () = = "") return "";
  string r = ""; for (int i = 0; i < s.length i++) R = = "&#" + ((int) s[i]).
  ToString () + ";";
 return R; The public string Rematchevaluator (Match m) {return (char) int. Parse (M.groups[1]. Value)).
 ToString (); ///<summary>///asp.net converts a 16-bit & #编码转为对应的字符串///</summary>///<param name= "s" >16 into a code-bit encoded string
 </param>///<returns>16 code-bit encoded string corresponding to string </returns> public string unicodecodebittostring (string s) {if (string. IsNullOrEmpty (s) | |
  S.trim () = = "") return ""; Regex rx = new Regex (@ "&# (\d+);", Regexoptions.compiled); Return RX.
 Replace (S, rematchevaluator);
  } protected void Page_Load (object sender, EventArgs e) {string s = "asp.net region code bit string";
  s = stringtounicodecodebit (s);//Convert to & #编码 Response.Write (s);
  Response.Write ("\ n");
 s = unicodecodebittostring (s);//& #编码转为字符串 Response.Write (s); }
}

The JavaScript version can refer to the following:

function Uncode (str) {//& #编码转换成字符 return
  str.replace (/&# x)? ( [^&] {1,5});? /g, function (A, B, c) {return
   String.fromCharCode (parseint (c, B, 16:10))
;} function encode (str) {//convert character to & #编码
  var a = [], i = 0;
  for (; i < str.length;) A[i] = Str.charcodeat (i++);
  Return "&#" + a.join ("; &#") + ";";
}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.