JusGellin Posted September 5, 2008 Posted September 5, 2008 I'm trying to substitute what's in brackets with an ascii character for the value that's in the brackets. For the following I want [05] to become ascii character 5. So the string below would become equivilant to "abcdf" & chr(5) & "dfd". How can I do this? The following doesn't work. Thanks $Dat = "abdf[05]dfd" ConsoleWrite(StringRegExpReplace($Dat, "\[(..)\]", chr("$1"))
Moderators SmOke_N Posted September 5, 2008 Moderators Posted September 5, 2008 I'm trying to substitute what's in brackets with an ascii character for the value that's in the brackets. For the following I want [05] to become ascii character 5. So the string below would become equivilant to "abcdf" & chr(5) & "dfd". How can I do this? The following doesn't work. Thanks $Dat = "abdf[05]dfd" ConsoleWrite(StringRegExpReplace($Dat, "\[(..)\]", chr("$1"))You can't. Nested functions (ie... your Chr()) are fired from right to left, so Chr() is fired before StringRegExpReplace() even searches for your pattern. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Szhlopp Posted September 5, 2008 Posted September 5, 2008 I'm trying to substitute what's in brackets with an ascii character for the value that's in the brackets. For the following I want [05] to become ascii character 5. So the string below would become equivilant to "abcdf" & chr(5) & "dfd". How can I do this? The following doesn't work. Thanks $Dat = "abdf[05]dfd" ConsoleWrite(StringRegExpReplace($Dat, "\[(..)\]", chr("$1")) $String = "Test [79] cha[58]rs" While 1 $regexp = StringRegExp($String, "(?:\[)([0-9]*)(?:\])", 1) If UBound($regexp) >= 1 Then $regexp = Chr($regexp[0]) $String = StringRegExpReplace($String, "(?:\[)([0-9]*)(?:\])", $regexp, 1) Else ExitLoop EndIf WEnd MsgBox(0, "", $String) RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+'
martin Posted September 5, 2008 Posted September 5, 2008 (edited) I'm trying to substitute what's in brackets with an ascii character for the value that's in the brackets. For the following I want [05] to become ascii character 5. So the string below would become equivilant to "abcdf" & chr(5) & "dfd". How can I do this? The following doesn't work. Thanks $Dat = "abdf[05]dfd" ConsoleWrite(StringRegExpReplace($Dat, "\[(..)\]", chr("$1"))$Dat = "abdf[05]dfd[13]" $ans = StringRegExpReplaCE($dat,"(\[)(\d\d)(\])","chr(" & "\2" & ")") ConsoleWrite($ans & @CRLF) Edited September 5, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
trancexx Posted September 5, 2008 Posted September 5, 2008 Not StringRegExp for this. Something else: $Dat = "abdf[05]dfd[13]" ConsoleWrite(Execute('"' & StringReplace(StringReplace($Dat, '[', '" & Chr('), ']', ') & "') & '"')) ♡♡♡ . eMyvnE
JusGellin Posted September 5, 2008 Author Posted September 5, 2008 Thanks for all the fast replies. Thanks SmOke_N for the explanation why mine didn't work. Szhlopp that is some really amazing clever code!!! It works great!! martin I thought yours would work, but it must be like what SmOke_N said of how it is fired. So it literally puts the Chr in the result instead of the ascii character Thanks again all.
martin Posted September 5, 2008 Posted September 5, 2008 Not StringRegExp for this. Something else: $Dat = "abdf[05]dfd[13]" ConsoleWrite(Execute('"' & StringReplace(StringReplace($Dat, '[', '" & Chr('), ']', ') & "') & '"'))That's no good if you have $Dat = "abdf[05]dfd[13]hhh[dotty][187654.hgt]" ConsoleWrite(StringReplace(StringReplace($Dat, '[', '" & Chr('), ']', ') & "')) What was the Execute bit for ? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
JusGellin Posted September 5, 2008 Author Posted September 5, 2008 (edited) Not StringRegExp for this. Something else: $Dat = "abdf[05]dfd[13]" ConsoleWrite(Execute('"' & StringReplace(StringReplace($Dat, '[', '" & Chr('), ']', ') & "') & '"')) Another great piece of code!!! Wow!! I thought of using Execute, but it didn't work where I was putting it - for the substitute part. thanks Edited September 5, 2008 by JusGellin
martin Posted September 5, 2008 Posted September 5, 2008 Thanks for all the fast replies. Thanks SmOke_N for the explanation why mine didn't work. Szhlopp that is some really amazing clever code!!! It works great!! martin I thought yours would work, but it must be like what SmOke_N said of how it is fired. So it literally puts the Chr in the result instead of the ascii character Thanks again all.Oh, I misunderstood. I thought you wanted Chr(23) written there instead of [23]. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
JusGellin Posted September 5, 2008 Author Posted September 5, 2008 Oh, I misunderstood. I thought you wanted Chr(23) written there instead of [23]. That's ok, sometimes it's hard to explain just what is being asked. Thanks
Szhlopp Posted September 5, 2008 Posted September 5, 2008 Thanks for all the fast replies.Thanks SmOke_N for the explanation why mine didn't work.Szhlopp that is some really amazing clever code!!! It works great!!martin I thought yours would work, but it must be like what SmOke_N said of how it is fired. So it literally puts the Chr in the result instead of the ascii characterThanks again all.Np. Glad I could. I don't know what tester you use but I've got a nice one in my sig FYI. RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+'
JusGellin Posted September 6, 2008 Author Posted September 6, 2008 Not StringRegExp for this. Something else: $Dat = "abdf[05]dfd[13]" ConsoleWrite(Execute('"' & StringReplace(StringReplace($Dat, '[', '" & Chr('), ']', ') & "') & '"'))Could you please explain how this works? My mind is really boggled to try to figure this out. This is really deep. I would like to see how your thinking came up with this. Thanks
trancexx Posted September 8, 2008 Posted September 8, 2008 Could you please explain how this works? My mind is really boggled to try to figure this out. This is really deep. I would like to see how your thinking came up with this. ThanksSure You said that you wanted to change "abdf[05]dfd" to "abcdf" & chr(5) & "dfd" What that code does is replaces [ to " & chr( and then ] to ) & " Then adds quotation marks at the beginning and to the end of that new string that is being executed afterward. It's all in one line just to make an impression ( ) , but to make it more understandable, here it is in full: $Dat = "abdf[05]dfd[13]" $Dat = StringReplace($Dat, '[', '" & Chr(') ; $Dat = abdf" & Chr(05]dfd" & Chr(13] $Dat = StringReplace($Dat, ']', ') & "') ; $Dat = abdf" & Chr(05) & "dfd" & Chr(13) & " $Dat = '"' & $Dat ; $Dat = "abdf" & Chr(05) & "dfd" & Chr(13) & " $Dat = $Dat & '"' ; $Dat = "abdf" & Chr(05) & "dfd" & Chr(13) & "" $Dat = Execute($Dat) ; $Dat = abdfdfd & @CR ConsoleWrite($Dat)oÝ÷ Ù8Z¶+jËZØʤ-«mêÞÂ)eméèº|×zn· +Èî²Ú^÷´w«{lJÚâ^Li²n¶*'ªí}ý²«¨¶)©®Þv«¨µ«¢+ØÀÌØíÐôÅÕ½ÐílÀÕulÄÍtÅÕ½Ðì() ½¹Í½±]ɥѡáÕÑ ÌäìÅÕ½ÐìÌäìµÀìMÑÉ¥¹IáÁIÁ± ÀÌØíаÅÕ½Ðì ÀäÈíl¤ ÀäÈí¤ ÀäÈí¤ü ÀäÈí¤ü ÀäÈít¤ÅÕ½Ðì°ÌäìÅÕ½ÐìµÀì ¡È ÌäìµÀìÅÕ½ÐìÀÌØìÈÅÕ½ÐìµÀìÅÕ½ÐìÀÌØìÌÅÕ½ÐìµÀìÅÕ½ÐìÀÌØìÐÅÕ½ÐìµÀìÌä줵ÀìÅÕ½ÐìÌä줵ÀìÌäìÅÕ½ÐìÌä줤 This code will deal with all kind of inputs (good and bad ones, no need to check it). ♡♡♡ . eMyvnE
martin Posted September 8, 2008 Posted September 8, 2008 (edited) $Dat = "abdf[05]dfd[13]" ConsoleWrite(Execute('"' & StringRegExpReplace($Dat,"(\[)(\d)(\d)?(\d)?(\])",'" & Chr(' & "$2" & "$3" & "$4" & ') & "') & '"')) This code will deal with all kind of inputs (good and bad ones, no need to check it). Now that I understand what was wanted, and why trancexx used execute, here is an improvement on the improved version by trancexx $Dat = "abdf[05]dfd[13]" ConsoleWrite(Execute('"' & StringRegExpReplace($Dat,"(\[)(\d{1,3})(\])",'" & Chr(' & "$2" & ') & "') & '"')) Edited September 8, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
JusGellin Posted September 12, 2008 Author Posted September 12, 2008 Thank you very much, trancexx for explaining this. I'm a rookie with regex, but I'm loving them!
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