As you know, in js, The encodeURIComponent method is a commonly used encoding method. However, due to work needs, this method is required in asp. I have checked a lot of information and there is no good method, finally, the following method is used to solve the problem.
Copy codeThe Code is as follows: <%
Function aspEncodeURIComponent (sStr)
AspEncodeURIComponent = myEncodeURIComponent (sStr)
%>
<Script language = "javascript" type = "text/javascript" runat = "server">
Function myEncodeURIComponent (sStr ){
Return encodeURIComponent (sStr );
}
</Script>
<%
End Function
%>
Note:
EncodeURIComponent Method
Encodes a text string into a valid component of a uniform resource identifier (URI.
EncodeURIComponent (encodedURIString)
The required encodedURIString parameter represents an encoded URI component.
Description
The encodeURIComponent method returns an encoded URI. If you pass the encoding result to decodeURIComponent, the initial string is returned. Because the encodeURIComponent method encodes all characters, note that if the string represents a path, for example,/folder1/folder2/default.html, the Slash will also be encoded. In this way, when the encoding result is sent to the web server as a request, it will be invalid. If the string contains more than one URI component, use the encodeURI Method for encoding.