Simpel Posted January 26, 2016 Posted January 26, 2016 (edited) Hi, I'm trying url encoding: Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "") Local $nChar $sData = "" For $i = 1 To $aData[0] $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 &= "%20" ; I changed from + to %20 Case Else $sData &= "%" & Hex($nChar, 2) EndSwitch Next Return $sData EndFunc ;==>_URIEncode But when I put in this: $sData = $cmdline[2] ; = Global $cPasteName = $aFileName[3] & $aFileName[4] & " " & $sTime _URlEncode($sData) and decode it back to check it than I get this: Global $cPasteName = $aFileName[3] & $aFileName[4] & So what is happening with the rest after the quotes and space? Regards, Conrad Edited January 27, 2016 by Simpel be more precise + changed title to [solved] and precise SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
BrewManNH Posted January 26, 2016 Posted January 26, 2016 I'm not seeing that line in the code you posted. Perhaps you need to explain what is going on in your script with more of an explanation, because as it stands you aren't making any sense. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Simpel Posted January 26, 2016 Author Posted January 26, 2016 Ok. I mark some text in my source code. Then I start via SciTE command a tool that brings that marked text to pastebin. So this marked text is inside of $cmdline[2] including all quotes and even " " with some space in it e.g. to part two variables in a messagebox. When I now call urlencode($cmdline[2]) it should be urlencoded this way: Global%20%24cPasteName%20%3D%20%24aFileName%5B3%5D%20%26%20%24aFileName%5B4%5D%20%26%20%22%20%22%20%26%20%24sTime But it will be: Global%20%24cPasteName%20%3D%20%24aFileName%5B3%5D%20%26%20%24aFileName%5B4%5D%20%26%20% When I decode it later to check then I miss some content: Global $cPasteName = $aFileName[3] & $aFileName[4] & It had to be: Global $cPasteName = $aFileName[3] & $aFileName[4] & " " & $sTime Now it's a bit more clear? Conrad SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
BrewManNH Posted January 26, 2016 Posted January 26, 2016 9 minutes ago, Simpel said: Now it's a bit more clear? Not in the slightest. Please post the whole script, or a reproducer that shows the problem. I'm getting that you're trying to send a URL to the function, but what you're getting back isn't clear to me or what that Global $cPasteName is or where you're getting the data from. Without seeing the script with the problem, I'd be guessing at best. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Simpel Posted January 26, 2016 Author Posted January 26, 2016 I have a little snippet of autoit code no matter what in the clipboard. At this point it is interesting that there is a qoutation mark followed by a space and another quotation mark. Example: MsgBox(0, "test", $someVariable & " " & $anotherVariable) ; This I put into the clipboard with <Strg>+<C> This snippet I will url-encode to post it. So I have to urlencode the content of the clipboard. Local $sDate = ClipGet() Local $sURlData = urlencode($sData) ; Take one of the url encoding funcs from post 1 you want ConsoleWrite($sURlData) Result should be: MsgBox(0%2C%20%22test%22%2C%20%24someVariable%20%26%20%22%20%22%20%26%20%24anotherVariable) But it will be: MsgBox(0%2C%20%22test%22%2C%20%24someVariable%20%26%20 Conrad SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
AutoBert Posted January 26, 2016 Posted January 26, 2016 (edited) Are i'm wrong or you mean HTML-Encode/Decode. This is a URL/Querystring: https://en.wikipedia.org/wiki/Query_string#URL_encoding This: https://en.wikipedia.org/wiki/Character_encodings_in_HTML is also a URL with querystring and explains how to en-/decode data in the way (i think) you want to do. Read both and try to understand why URLen-/decoding is the wrong way. Edited January 26, 2016 by AutoBert
Simpel Posted January 26, 2016 Author Posted January 26, 2016 Hi AutoBert. What I'm looking for is presented in your first link. I have to change my clipboard content to a url/querystring. All these three (_URL_Encode ; _URlEncode ; urlencode funcs from the first post) do this. But all these stop if the data in the clipboard sending to the urlencoding contains '" "'. SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
AutoBert Posted January 26, 2016 Posted January 26, 2016 10 minutes ago, Simpel said: Hi AutoBert. What I'm looking for is presented in your first link. I have to change my clipboard content to a url/querystring. All these three (_URL_Encode ; _URlEncode ; urlencode funcs from the first post) do this. But all these stop if the data in the clipboard sending to the urlencoding contains '" "'. I have tested @Progandy _URiEncode: ConsoleWrite(_URIEncode('Global $cPasteName = $aFileName[3] & $aFileName[4]' & " " & '21:13')&@CRLF) and the console output: Global%20%24cPasteName%20%3D%20%24aFileName%5B3%5D%20%26%20%24aFileName%5B4%5D%2021%3A13 shows me the string is complete, When you use @Progandy's URiDecode the String will be the same as the origin which was encoded.
Simpel Posted January 27, 2016 Author Posted January 27, 2016 @AutoBert: You manually put some single quotes inside the content. Try this: ; Just to have no problems running the compiler Local $sFileName[4] Local $sTime ; ---------- ; Put the next line into windows clipboard with <Strg><C> - It's just a snippet I want to send via querystring e.g. to pastebin. Global $cPasteName = $aFileName[3] & $aFileName[4] & " " & $sTime ; Run all with F5 Local $sDate = ClipGet() Local $sURlData = urlencode($sData) ; Take one of the url encoding funcs from post 1 you want ConsoleWrite($sURlData) What is your result? I guess it is: Global%20%24cPasteName%20%3D%20%24aFileName%5B3%5D%20%26%20%24aFileName%5B4%5D%20%26%20% But it has to be: Global%20%24cPasteName%20%3D%20%24aFileName%5B3%5D%20%26%20%24aFileName%5B4%5D%20%26%20%22%20%22%20%26%20%24sTime Why is this missing? 22%20%22%20%26%20%24sTime Conrad SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
AutoBert Posted January 27, 2016 Posted January 27, 2016 (edited) I can't try your's because of your not filled variables. The UriEnCode and the URiDecode func form @Progandy are working proberly together, the erorr is somewher else in your script. I think the variable $sTime is only declared but not populated. To get that what you want it had to be: $Time='$Time' Make a small runable reproducer script (with no useraction, use ClipPut instead) where the errors occur. Edited January 27, 2016 by AutoBert
Simpel Posted January 27, 2016 Author Posted January 27, 2016 (edited) Hi, now I found my mistake. First of all all three urlencodings are correct. Try this: expandcollapse popup; This is just some text & " " & some more <--- Put it into the parameters. Goto view - parameters or <Shift><F8>. Local $sCmdData Local $sURlData If $cmdline[0] > 1 Then For $i = 1 To $cmdline[0] $sCmdData &= $cmdline[$i] $sURlData &= _URIEncode($cmdline[$i]) Next ConsoleWrite("$cmdlineraw: " & $cmdlineraw & @CRLF) ConsoleWrite("_URIEncode($cmdlineraw): " & _URIEncode($cmdlineraw) & @CRLF) ConsoleWrite("$cmdline[1]: " & $cmdline[1] & @CRLF) ConsoleWrite("$cmdline[7]: " & $cmdline[7] & "|||" & @CRLF) ConsoleWrite("$sCmdData: " & $sCmdData & @CRLF) ConsoleWrite("$sURlData: " & $sURlData & @CRLF) Else ConsoleWrite(@CRLF & "Nothing in $cmdlineraw. Put the first line into the parameters. Goto view - parameters or <Shift><F8>." & @CRLF & @CRLF) EndIf Exit Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "") Local $nChar $sData = "" For $i = 1 To $aData[0] $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 &= "%20" ; I changed to %20 instead of + Case Else $sData &= "%" & Hex($nChar, 2) EndSwitch Next Return $sData EndFunc ;==>_URIEncode Console output: 01 $cmdlineraw: /ErrorStdOut "C: ... au3" This is just some text & " " & some more 02 _URIEncode($cmdlineraw): %2FErrorStdOut%20%22C%3A ... au3%22%20This%20is%20just%20some%20text%20%26%20%22%20%22%20%26%20some%20more%20%20%20 03 $cmdline[1]: This 04 $cmdline[7]: ||| 05 $sCmdData: Thisisjustsometext& &somemore 06 $sURlData: Thisisjustsometext%26%20%26somemore As I said earlier I had some text (snippets of autoit) inside $cmdline. I didn't know that every space inside $cmdlineraw will set the next part of it into another array field of $cmdline[x]. So a space seemed to work as a delimiter. Console output #03 shows that only "This" is inside $cmdline[1]. Because of the following space "is" is inside $cmdline[2]. Now the riddle with " " is solved for me. $cmdline[7] contains " ". This preserves the space because it's written in quotes. You can see it in console output #04. #05 shows the whole $cmdline[x] together. That's not what I wanted. So I have to change my code to use only $cmdlineraw. Are there clear rules what $cmdlineraw is containing before the first parameter. How can I trim it to only all parameters? Regards, Conrad Edited January 27, 2016 by Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
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