Jump to content

String un/escape en/decode?

Recommended Posts

Hi, i'm looking for some functionality that can unescape strings that has been encoded.

First and foremost i'm looking for a plain alternative to javascripts unescape()

Func _URIDecode($sData)
; Prog@ndy
Local $aData = StringSplit(StringReplace($sData,"+"," ",0,1),"%")
$sData = ""
For $i = 2 To $aData[0]
$aData[1] &= Chr(Dec(StringLeft($aData[$i],2))) & StringTrimLeft($aData[$i],2)
Return BinaryToString(StringToBinary($aData[1],1),4)

It only works if all characters are escaped..it can not be mixed. for an example, it fails if the string contains a unescaped %..

$myres1 = _URIDecode('Jo%C3%A3o%20Guimar%C3%A3es%20Rosa')
ConsoleWrite($myres1 & @CRLF) ; Outputs: "João Guimarães Rosa" - (Works fine!)

$myres2 = _URIDecode("I was about 99% done!")
ConsoleWrite($myres2 & @CRLF) ; Outputs: "I was about 99"

So..before is start improving the above snippet, do a library exist that can handle these things?

(HTML en/decoding would be nice)


Hmm..i just tried javascripts method.. it also fails when single %... offcourse.. hmm.. nevermind.

My question is answered.. ill leave the post

Edited by squadjot
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...