Sometimes there may be such a demand that I use in the background:
Copy Code code as follows:
Httputility.urlencode (str, System.Text.Encoding.UTF8);
The URL is encoded, the front desk JS need to use this content, this time need to decode:
Code
Copy Code code as follows:
/**
* URL encoding
**/
Shengutils.encode = function (unzipstr) {
var zipstr= "";
var strspecial= "!\" #$%& ' () *+,/:;<=>? []^`{|} ~%";
var tt= "";
for (Var i=0;i<unzipstr.length;i++) {
var chr = Unzipstr.charat (i);
var c=shengutils.stringtoascii (CHR);
tt + + chr+ ":" +c+ "n";
if (parseint ("0x" +c) > 0x7f) {
Zipstr+=encodeuri (Unzipstr.substr (i,1));
}else{
if (chr== "")
zipstr+= "+";
else if (Strspecial.indexof (CHR)!=-1)
zipstr+= "%" +c.tostring (16);
Else
ZIPSTR+=CHR;
}
}
return zipstr;
}
/**
* URL decoding
**/
Shengutils.decode=function (ZIPSTR) {
var uzipstr= "";
for (Var i=0;i<zipstr.length;i++) {
var chr = Zipstr.charat (i);
if (Chr = = "+") {
uzipstr+= "";
}else if (chr== "%") {
var asc = zipstr.substring (i+1,i+3);
if (parseint ("0x" +asc) >0x7f) {
Uzipstr+=decodeuri ("%" +asc.tostring () +zipstr.substring (i+3,i+9). toString ());
i+=8;
}else{
Uzipstr+=shengutils.asciitostring (parseint ("0x" +asc));
i+=2;
}
}else{
uzipstr+= CHR;
}
}
return uzipstr;
}
Shengutils.stringtoascii=function (str) {
Return str.charcodeat (0). toString (16);
}
shengutils.asciitostring = function (Asccode) {
Return String.fromCharCode (Asccode);
}