问题
I want to write the two functions that is used for asp.net and asp. I want to write two version. This function is used url encode and decode. Now, I got a new problem. This is how to work server.urlencode. So, how to implement this url encode function. I have url decode function for asp. I try to get url encode function for asp. So that, I can write url encode and decode in asp.net. Please, help me.
This is url decode function.
Function URLDecode(sConvert)
Dim aSplit
Dim sOutput
Dim I
If IsNull(sConvert) Then
URLDecode = ""
Exit Function
End If
' convert all pluses to spaces
sOutput = REPLACE(sConvert, "+", " ")
' next convert %hexdigits to the character
aSplit = Split(sOutput, "%")
If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1
sOutput = sOutput & _
Chr("&H" & Left(aSplit(i + 1), 2)) &_
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If
URLDecode = sOutput
End Function
I got this.
回答1:
VBScript is a hog when it comes to string parsing so here is the same decode done in JScript:
<script language="JScript" runat="server">
// This function decodes the any string
// that's been encoded using URL encoding technique
function URLDecode(psEncodeString)
{
return unescape(psEncodeString);
}
</script>
http://www.kamath.com/codelibrary/cl006_url.asp
.NET has HttpServerUtility.UrlEncode and HttpServerUtility.UrlDecode functions built in.
http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx
来源:https://stackoverflow.com/questions/6490247/how-to-use-url-encoding-function-between-asp-net-and-asp