AzKay Posted May 29, 2009 Share Posted May 29, 2009 Ive got this string: 123abc!@#$%^&*()_+ If I run it through a POST request on a website, it converts it to: 123abc%21%40%23%24%25%5E%26*%28%29_%2B+ What encoding is it? # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
Pain Posted May 29, 2009 Share Posted May 29, 2009 First I thought it was escape() or encodeURI() but they gave a slightly different output. But I guess you can make your own function in less than a minute since the output is % + hexcode of the character. Link to comment Share on other sites More sharing options...
KaFu Posted May 29, 2009 Share Posted May 29, 2009 (edited) Had this snippet, don't know from where , Kudos to the author!ConsoleWrite(URLEncode("123abc!@#$%^&*()_+ ") & @crlf) Func URLEncode($urlText) $url = "" For $i = 1 To StringLen($urlText) $acode = Asc(StringMid($urlText, $i, 1)) Select Case ($acode >= 48 And $acode <= 57) Or _ ($acode >= 65 And $acode <= 90) Or _ ($acode >= 97 And $acode <= 122) $url = $url & StringMid($urlText, $i, 1) Case $acode = 32 $url = $url & "+" Case Else $url = $url & "%" & Hex($acode, 2) EndSelect Next Return $url EndFunc ;==>URLEncodeEdit: I bet URL encoding is defined in some standard, but don't know which. I was the result of my function does not match yours to the point, * and _ didn't seem to be converted by your script (to emulate maybe explicitly exclude these characters from the URLEncode() function).Edit2: Guess it's something like this http://en.wikipedia.org/wiki/Percent-encoding Edited May 29, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Popular Post ProgAndy Posted May 29, 2009 Popular Post Share Posted May 29, 2009 (edited) I wrote some functions including UTF-8 conversion Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"") Local $nChar $sData="" For $i = 1 To $aData[0] ; ConsoleWrite($aData[$i] & @CRLF) $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar,2) EndSwitch Next Return $sData EndFunc 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) Next Return BinaryToString(StringToBinary($aData[1],1),4) EndFunc MsgBox(0, '', _URIDecode(_URIEncode("testäöü fv")))Edit 2012: Fixed bug in _URIEncode, removed debug output Edited September 26, 2012 by ProgAndy Chiitus, Zohar, algiuxas and 6 others 8 1 *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
KaFu Posted May 29, 2009 Share Posted May 29, 2009 Nice snippet ProgAndy , saved... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
lsakizada Posted August 24, 2009 Share Posted August 24, 2009 (edited) I wrote some functions including UTF-8 conversion Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData,4),1),"") Local $nChar $sData="" For $i = 1 To $aData[0] ConsoleWrite($aData[$i] & @CRLF) $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48-57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar,2) EndSwitch Next Return $sData EndFunc 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) Next Return BinaryToString(StringToBinary($aData[1],1),4) EndFunc MsgBox(0, '', _URIDecode(_URIEncode("testäöü fv"))) ProgAndy, My question may sound stupid, but how do I know whether string needs to be decoded or encoded? let me explain, I am taking part string from an URL box of IE automaticaly (Actually, its a value of one of the get method variables) and wants to know if this string is decoded or encoded. E.g. Sometimes this values come in this form; %E0%E1%F8%E4%ED#876 and some times its just a UTF string (locale specific string that can be read by human). For example: http://www.robolo.co.il/SearchResults.html?cx=001994764102475033040%3A3o-v0ytfm9g&ie=windows-1255&cof=FORID%3A9&q=english#198 http://www.robolo.co.il/SearchResults.html?cx=001994764102475033040%3A3o-v0ytfm9g&ie=windows-1255&cof=FORID%3A9&q=%EE%F9%E4&x=45&y=15#892 Are there any functions such as IsEncodedURI or IsDecodedURI? See the "q=" parameter BTW: Your code is wonderful. Thanks for sharing it. >_< Edited August 24, 2009 by lsakizada Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
jvanegmond Posted August 24, 2009 Share Posted August 24, 2009 Hi, you should be able to decode any URL string and get the same result. Even if there are no encoded characters in there. So to decode you can just call a decode function. No need to check with a IsEncoded function. Greetings, Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
tele123 Posted January 29, 2012 Share Posted January 29, 2012 (edited) ą, ń, ę, ż, dż, ź, ó, ł, ś, ć, ( from file ) ---> ±, ę, ż, dż, Ľ, ó, ł, ¶, ć, ( from url ) How to change this? : ±, ę, ż, dż, Ľ, ó, ł, ¶, ć, ---> ą, ń, ę, ż, dż, ź, ó, ł, ś, ć, slawekc The text is encoded in ISO8859-2. If you want, you can use the following function to get the text in ANSI (works only for Polish): [ code='text' ] ( Popup ) Func ISOtoANSI($sText) ; http://en.wikipedia.org/wiki/Polish_code_pages $sText = StringReplace($sText, Chr(Dec("A1")), "Ą") $sText = StringReplace($sText, Chr(Dec("A6")), "Ś") $sText = StringReplace($sText, Chr(Dec("AC")), "Ź") $sText = StringReplace($sText, Chr(Dec("B1")), "ą") $sText = StringReplace($sText, Chr(Dec("B6")), "ś") $sText = StringReplace($sText, Chr(Dec("BC")), "ź") Return $sText EndFunc ;==>ISOtoANSI [indent=1] Edited February 14, 2012 by tele123 Link to comment Share on other sites More sharing options...
babailiica Posted September 26, 2012 Share Posted September 26, 2012 Here is my rulencode and urldecode functions. UTF8 is supported and functions are compliant with RFC 3986. The urlencode function accepts a seccond parameter - if true (default) it will encode spaces as plus. If false - the space will be encoded as "%20" (not compliant) expandcollapse popupFunc urlencode($str, $plus = True) Local $i, $return, $tmp, $exp $return = "" $exp = "[a-zA-Z0-9-._~]" If $plus Then $str = StringReplace ($str, " ", "+") $exp = "[a-zA-Z0-9-._~+]" EndIf For $i = 1 To StringLen($str) $tmp = StringMid($str, $i, 1) If StringRegExp($tmp, $exp, 0) = 1 Then $return &= $tmp Else $return &= StringMid(StringRegExpReplace(StringToBinary($tmp, 4), "([0-9A-Fa-f]{2})", "%$1"), 3) EndIf Next Return $return EndFunc Func urldecode($str) Local $i, $return, $tmp $return = "" $str = StringReplace ($str, "+", " ") For $i = 1 To StringLen($str) $tmp = StringMid($str, $i, 3) If StringRegExp($tmp, "%[0-9A-Fa-f]{2}", 0) = 1 Then $i += 2 While StringRegExp(StringMid($str, $i+1, 3), "%[0-9A-Fa-f]{2}", 0) = 1 $tmp = $tmp & StringMid($str, $i+2, 2) $i += 3 Wend $return &= BinaryToString(StringRegExpReplace($tmp, "%([0-9A-Fa-f]*)", "0x$1"), 4) Else $return &= StringMid($str, $i, 1) EndIf Next Return $return EndFunc Link to comment Share on other sites More sharing options...
guinness Posted September 26, 2012 Share Posted September 26, 2012 babailiica, This would have been best suited in the examples section and not digging up an old post such as this. Secondly, the best version I've seen has be ProgAndy's which features in the WinHTTP UDF. Thanks for your contribution and welcome to the Forum. GuyFromNJo 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now