Unencoding a text string

Results 1 to 3 of 3

Thread: Unencoding a text string

  1. #1
    Join Date
    Dec 1969

    Default Unencoding a text string

    I currently have a number of text strings being returned to me. They are encoded in the same way that Server.URLEncode will encode a string. I cannot change the way that the strings are returned. However, I would like to decode these strings.<BR><BR>Ex.<BR>Continue%20on%20Atkinson%20 Dr%20and%20go%20East%20for%200.3%20miles<BR><BR>ne eds to be changed to <BR><BR>Continue on Atkinson Dr and go East for 0.3 miles<BR><BR>In most of the strings there are many more codes than just %20, this is just an example. I need to return this to the normal form. Are there any objects or functions that can do this for me? I guess this would be the opposite of Server.URLEncode, and be such as what Server.URLDecode would be.<BR><BR>Thanks

  2. #2
    AspHead Guest

    Default RE: Unencoding a text string

    Theres no URLDecode given with ASP (that I know of). Heres what I have used in the past. Also, if you want to write your own, all the encoding (except &#039+&#039) are HEX values. Just convert them and off you go. <BR><BR>Heres the code for your convienence:<BR><BR>Function URLDecode(strIn)<BR>&#039Copied from ASP PAGES 2.0 from wrox press<BR><BR>Dim strOut,intPos,strLeft,strRight<BR><BR>strOut =""<BR><BR>intPos = instr(strIn, "+")<BR>Do While IntPos<BR>strLEft=""<BR>strRight = ""<BR>If intPos &#062;1 then strLeft = Left(strIn, intPos -1)<BR>If intPos &#060; Len(strIn) then strRight = Mid(strIn,intPos+1)<BR>strin = strLeft & " " & strRight<BR>intPos = Instr(strIn, "+")<BR>intLoop = IntLoop + 1<BR>Loop<BR><BR>intPos = instr(strIn,"%")<BR>do while intPos<BR>IF intPos &#062;1 then strOut = strOUt & left(strIn,intPos-1)<BR>strout=strout & chr(cint("&H" & Mid(strIn,intpos+1,2)))<BR>if intPos&#062; (len(strIn)-3) then<BR> strIn=""<BR>Else<BR> strIn = mid(strIn,intPos+3)<BR>end if<BR>intpos = instr(strIn,"%")<BR>loop<BR><BR>URLDecode = strout & strIn<BR>End Function

  3. #3
    Join Date
    Dec 1969

    Default CROSSPOST but try this anyway

    Bill (no, not me!) crossposted this. SHAME ON HIM! Anyway, see the "asp" forum as well as here. <BR><BR>****************************************** ********************<BR>AspHead wrote:<BR>&#062; Theres no URLDecode given with ASP (that I know of). <BR><BR>********************<BR><BR>Here&#039s the answer I gave in the ASP forum:<BR><BR>Are you aware that VBS code can call JS subroutines?<BR><BR>Are you aware that JS has a *built in* function that decodes encoded URLs?<BR><BR>So:<BR><BR>&#060;SCRIPT Language=JScript RUNAT=Server&#062;<BR>function decode( str )<BR>{<BR> return unescape( str ); // call builtin function<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;%<BR>...<BR>decodedVersi on = decode( codedVersion ) &#039 call the JS routine<BR>...<BR>%&#062;<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