Server.URLEncode without using Server.URLEncode

Results 1 to 3 of 3

Thread: Server.URLEncode without using Server.URLEncode

  1. #1
    Join Date
    Dec 1969

    Default Server.URLEncode without using Server.URLEncode

    I need to be able to perform the same operation as Server.URLEncode, but without using Server.URLEncode (I don&#039t have a reference to the Scripting Context of ASP, thus Server will not work).<BR>I&#039m creating a VB DLL where I need to do this, and I need some VB code to handle this.<BR>Thanks!!<BR>

  2. #2
    Steve Cimino Guest

    Default RE: Server.URLEncode without using Server.URLEncod

    You can probably download the ASP Reference table from microsoft&#039s site. If you&#039re using Visual Studio, it&#039s already there (Microsoft Active Server Pages Type Library).<BR><BR>Otherwise, you&#039re going to have to do a lot of searching on the string, and replace characters inside a Select Case statement.<BR><BR>Good Luck!

  3. #3
    Join Date
    Dec 1969

    Default RE: Server.URLEncode without using Server.URLEncod

    Well, in VBScript code, the function *could* look something like this:<BR><BR>&#060;%<BR>noEncode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789"<BR><BR>Function myURLEncode( msg )<BR>&nbsp;&nbsp;&nbsp;&nbsp;out = ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;For i = 1 To Len( msg )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;ch = Mid(msg,i,1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;If InStr(noEncode,ch) &#062; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out = out & ch<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out = out & "%" & Right(Hex(Asc(ch)+256),2)<BR>&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;Next<BR>&nbsp;&nbsp; &nbsp;&nbsp;myURLEncode = out<BR>End Function<BR>%&#062;<BR><BR>I add 256 (100 hex!) to the ASC value to be sure to get two hex digits in the final result, as required by URL encoding. Since I then do Right(...,2), the leading 1 disappears.<BR><BR>You should be able to use that code essentially unchanged in VB.<BR><BR>(And if it turns out that there are other characters other than the alphanumerics that don&#039t need to be encoded, you can just add them to that "noencode" string without changing anything else.)<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts