Convert a Perl CGI code to ASP

I need to convert a Perl CGI script to ASP vb script, becuase I require to convert the data into my ASP program. and I have no idea about the CGI.

This is the CGI script

sub dc_decode {
    my $todecode = shift;
    return undef unless defined($todecode);
    $todecode =~ tr/+/ /;       # pluses become spaces
    $todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge;
    $todecode =~ s/\r\n/\n/g;;
    return $todecode;
}

Do anyone know the ASP version of the above script?
LVL 1
billsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sybeCommented:
in VBScript you can use the UnEscape() function for this.

<%
MyVar = Unescape(Myvar)
%>

But maybe you don't have to use this function at all. The perl function is used to convert a (url-encoded) querystring into something that was originally posted. I don't know in what context you need to use it, but in ASP, the querystring is automatically urldecoded when you ask individual items of the Request object.

So you will need to decode if you use the complete querystring

<%
Response.write Unescape(Request.Quersystring)
%>

But you don't need to decode for each formfield:

<%
Response.write Request.Querystring("fieldname")
%>

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StormyWatersCommented:
Here is another alternative:
http://flangy.com/dev/asp/urldecode.html
0
billsonAuthor Commented:
thx sybe  and StormyWaters, the return code is correctly display in ASP page, but if I use Windows Script Hosting - vbs file to get the output. the return code is mess-up. Any idea?
0
sybeCommented:
What is the input you are giving to the Windows Scripting Host?
0
billsonAuthor Commented:
I have inputed Chinese character (BIG5 character set) and use the following script to encode in WSH, ASP also. ASP can return what I inputed. But WSH just return the "??" for those chinese character. I am using WinXP Chinese Traditional Version.

Since I need to convert 10000 message to the new asp system. I prefer to use WSH to prevent ASP timeout. But if no solution for WSH, I will try to use ASP to do so.

Function URLEncode(Text)
    Dim acode
    Temp = ""
    For i = Len(Text) To 1 Step -1
        acode = Asc(Mid(Text, i, 1))
            if (acode >= 48 AND acode <= 57) OR (acode >= 65 AND acode <= 90) OR (acode >= 97 AND acode <= 122) then
                  Temp = Mid(Text, i, 1) & Temp
            elseif acode = 32 then
                  Temp = "+" & Temp
            else
                  Temp = "%" & Hex(acode) & Temp
            end if
    Next
      URLEncode = Temp
End Function
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.