argumentum Posted April 16, 2021 Share Posted April 16, 2021 (edited) StringFormat("\\\\server\\share") will return "\\server\share". That is nice but what about the other way around ? Do I have to do StringReplace() each ( \t, \r, \n , etc. ) or is there a simpler way ?. Thanks. solved @ https://www.autoitscript.com/forum/topic/205642-solved-stringformat-where-is-the-stringformatbuilder/?do=findComment&comment=1479967 Edited April 16, 2021 by argumentum solved =) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
seadoggie01 Posted April 16, 2021 Share Posted April 16, 2021 (edited) Func StringUnFormat($sText) Return StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace($sText, "\", "\\"), "%", "%%"), @CRLF, "\r\n"), @TAB, "\t"), @LF, "\n"), @CR, "\r") EndFunc Is this what you're looking for? I don't think there's another way to do it Edit: Added \\ and %% Edited April 16, 2021 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
argumentum Posted April 16, 2021 Author Share Posted April 16, 2021 that's my question. There is also "%" to "%%" and "\" to "\\". Maybe the gods of StringRegExpReplace() have a simple and fast, all encompassing formula for this Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
seadoggie01 Posted April 16, 2021 Share Posted April 16, 2021 You can't do that with a [single] regular expression, since a newline/tab can't be replaced with the respective escaped equivalent... right? All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
argumentum Posted April 16, 2021 Author Share Posted April 16, 2021 @seadoggie01, I can understand quantum entanglement, the reason for matter to exist, etc., but this darn Regular Expressions I have no clue. A string in a variable is just a string. seadoggie01, Musashi, wolflake and 1 other 4 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
mikell Posted April 16, 2021 Share Posted April 16, 2021 52 minutes ago, argumentum said: this darn Regular Expressions nasty guy $str = "\\server\share" & @cr & @tab & "an%other" $s = StringRegExpReplace($str, '([\\%\r\t])', "$1$1") Msgbox(0,"", $str & @crlf & @crlf & $s) Gianni and FrancescoDiMuro 2 Link to comment Share on other sites More sharing options...
Gianni Posted April 16, 2021 Share Posted April 16, 2021 sorry for the intrusion, but it's only for a small question. Can you translate the nested string expression posted by @seadoggie01 in the second post into a single regexp pattern? that is: to change in the input string all the characters of the first group one by one with the corresponding characters of the second group? example: "Bread Whole Bull Ball", "aou", "eaa" -> should result in -> "Breed Whale Ball Bell" explanation: "Bread Whole Bull Ball": input string "aou": characters to search for "eaa": characters to replace that is, replace all "a" with "e"; all "o" with "a" and all "u" with "a" "Breed Whale Ball Bell": outgoing string Thanks Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Nine Posted April 16, 2021 Share Posted April 16, 2021 45 minutes ago, Chimp said: Breed Whale Ball Bell I remember the good old days of "Lucy in the Sky with Diamond". Seems like a flash back Musashi 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted April 16, 2021 Share Posted April 16, 2021 (edited) @argumentum, do you mean something like this? $sOut = "\\server\share\n\r\t" & @cr & @tab & "an%other" $sIn = Execute("'" & StringRegExpReplace($sOut, "([\\%])|(\[nrt])", "' & '$1$1' & ('$2' ? '\\$2' : '') & '") & "'") ConsoleWrite($sIn & @LF) ConsoleWrite(StringFormat($sIn) & @LF) Of course there's double cheating here: first I use two function calls, second it's impossible to "unformat" variables' values (which is what StringFormat is meant for in the first place). EDIT: forget the completely idiotic code above! ; converting these: ; \ to \\ ; % to %% $sOut = "\\server\share\n\r\t" & @cr & @tab & "an%other" $sIn = StringRegExpReplace($sOut, "([\\%])", "$1$1") ConsoleWrite($sIn & @LF & @LF) ConsoleWrite(StringFormat($sIn) & @LF) But later posts reveal that you're after something else. See below. Edited April 16, 2021 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
argumentum Posted April 16, 2021 Author Share Posted April 16, 2021 I love chatting when is masterful The word "unformat" is because I could not come up with a better name for the function that would build the "sprintf()" string. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
argumentum Posted April 16, 2021 Author Share Posted April 16, 2021 ;====================================================================== $str = "\\server\share\n\r\t" & @CRLF & @TAB & "an%other" $s = StringRegExpReplace($str, '([\\%\r\t])', "$1$1") ConsoleWrite('=== >' & $s & '< === this should be a one liner'& @CRLF) #cs === >\\\\server\\share\\n\\r\\t an%%other< === this should be a one liner #ce ;====================================================================== $sOut = "\\server\share\n\r\t" & @CRLF & @TAB & "an%other" $sIn = Execute("'" & StringRegExpReplace($sOut, "([\\%])|(\[nrt])", "' & '$1$1' & ('$2' ? '\\$2' : '') & '") & "'") ConsoleWrite('=== >' & $sIn & '< === this should be a one liner'& @CRLF) #cs === >\\\\server\\share\\n\\r\\t an%%other< === this should be a one liner #ce ;====================================================================== Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
jchd Posted April 16, 2021 Share Posted April 16, 2021 (edited) My proposal above is terrible as was uselessly complicated, sorry. If you insist on converting actual CRs, LFs & TABs, then: ; converting these: ; \ to \\ ; % to %% ; newline to \n ; carriage return to \r ; tab to \t $sOut = "\\server\share\n\r\t" & @cr & @tab & "an%other" $sIn = Execute("'" & StringRegExpReplace($sOut, "([\\%]|\n|\r|\t)", "' & ('$1' = '\\' ? '\\\\' : '') & ('$1' = '%' ? '%%' : '') & ('$1' = @LF ? '\\n' : '') & ('$1' = @CR ? '\\r' : '') & ('$1' = @TAB ? '\\t' : '') & '") & "'") ConsoleWrite($sIn & @LF & @LF) ConsoleWrite(StringFormat($sIn) & @LF) and the result is a one-liner. Edited April 16, 2021 by jchd argumentum 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
argumentum Posted April 16, 2021 Author Share Posted April 16, 2021 Thanks a bunch !!!. It may sound/look useless but having the counterpart function is good to have Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
jchd Posted April 16, 2021 Share Posted April 16, 2021 I'm only half satisfied with that because it looks really heavy, but I've no magic wand in mind right now ... and may never have one. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
argumentum Posted April 16, 2021 Author Share Posted April 16, 2021 Hence my request. If it looks heavy as "C++" running speed, what's the speed of "au3" ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
mikell Posted April 17, 2021 Share Posted April 17, 2021 (edited) 11 hours ago, Chimp said: to change in the input string all the characters of the first group one by one with the corresponding characters of the second group? As there are multiple requirements I can't see how to avoid the use of an external container $sd = ObjCreate("Scripting.Dictionary") $sd.add("a", "e") $sd.add("o", "a") $sd.add("u", "a") $str = "Bread Whole Bull Ball" $r = Execute("'" & StringRegExpReplace($str, "(\w)", "' & ($sd.exists('$1') ? $sd.item('$1') : '$1') & '") & "'") Msgbox(0,"", $r) Edit : something simpler - but more limited $s = "Bread Whole Bull Ball" $in = "aou" $out = "eaa" $res = Execute('"' & StringRegExpReplace($s, '([aou])', '" & StringMid($out, StringInStr($in, "$1"), 1) & "') & '"') Msgbox(0,"", $res) Edited April 17, 2021 by mikell wolflake, Gianni and argumentum 3 Link to comment Share on other sites More sharing options...
Gianni Posted April 17, 2021 Share Posted April 17, 2021 Thanks Mikell, by simply changing Execute() to Consolewrite() I was able to see what that line of the first script does. Produces a single 851-character AutoIt instruction to parse every single letter of the input string. Brilliant and expensive at the same time; still interesting. so I can infer that there is no "internal" way to ask regexp to scan a sequence of characters and replace them with another set of substitutes. Thanks a lot @mikell, always something interesting from you. p.s. @argumentum, sorry for my little hijacking. I'm leaving right now ... bye argumentum and wolflake 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jchd Posted April 17, 2021 Share Posted April 17, 2021 18 minutes ago, Chimp said: so I can infer that there is no "internal" way to ask regexp to scan a sequence of characters and replace them with another set of substitutes. That's simply because regexes (not only PCRE) are tools to match pieces of text but have no internal support for replacement, nor any other text processing. StringRegexReplace and similar features allow you to grab matched pieces from a subject and allow you to glue them verbatim at will, but there is no regex primitive to perform any transformation of the text pieces. Furthermore, even if PCRE offers built-in If-Then-Else and even recursive constructs, none of them is available in the "replace pattern": it isn't a regular regex pattern, just a string with interpolation of sequences similar to regex back-references: $1,$2,... or \1,\2,... or ...$(17),$(18),... This implies that applying any transformation to any piece of text output by the match phase has to be done by external code and --for a character translation-- a translation table in an external container, just as @mikell said. In Perl regex have support for Perl interpolation, that is invoke Perl code when certain matching condition occurs, but it's still code external to regex which will be acting then. seadoggie01, Gianni, argumentum and 1 other 3 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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