funkey Posted December 29, 2023 Share Posted December 29, 2023 Hi, I use v3.3.14.5 here and have a bug. Local $sBug = StringReplace("123456789", 2, "a") ConsoleWrite($sBug & " - replacements: " & @extended & " <-- expected 1" & @CRLF) This is the result 1a3456789 - replacements: 0 <-- expected 1 Is this already solved in v3.3.16.1 I don't want to update now... Thanks for your answers! Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Andreik Posted December 29, 2023 Share Posted December 29, 2023 (edited) Not yet. PS: has this been reported? Edited December 29, 2023 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
funkey Posted December 29, 2023 Author Share Posted December 29, 2023 Don't know. Just found it. Thanks for testing. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Andreik Posted December 29, 2023 Share Posted December 29, 2023 (edited) I'm not sure if this is by design or a bug. Since the function it's named StringReplace() the search string should be a string not an integer. If it's a string it works fine. Yet since AutoIt uses a variant implementation to represent variables and does all kind of conversions probably should deal internally and make sure the parameters are converted to strings. The interesting part it's that in this code only the first 2 it's replaced with an a: Local $sBug = StringReplace("1234567892", 2, "a") ConsoleWrite($sBug & " - replacements: " & @extended & " <-- expected 1" & @CRLF) and the result Quote 1a34567892 - replacements: 0 <-- expected 2 I would like to know more about what AutoIt does internally but for now even if it's not enforced I would say it's up to programmer to be sure that the search string it's really a string. Edited December 29, 2023 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
funkey Posted December 29, 2023 Author Share Posted December 29, 2023 I wanted it to be an integer for replacing characters at position. This is the second way StringReplace() works. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Nine Posted December 29, 2023 Share Posted December 29, 2023 Why do you need @extended to report 1 when you ask to change 1 char (or string) with another based on position ? Check @error instead ! water 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...
funkey Posted December 29, 2023 Author Share Posted December 29, 2023 I don't need it. But the behaviour is not consistently. I just expected there to be a '1' in @extended. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Nine Posted December 29, 2023 Share Posted December 29, 2023 Well, since it is useless, I don't think any dev in here will put 1ms to please this eccentricity... “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...
argumentum Posted December 29, 2023 Share Posted December 29, 2023 14 minutes ago, Nine said: Well, since it is useless, based on https://www.autoitscript.com/autoit3/docs/functions/StringReplace.htm we either fix the code or fix the help. funkey 1 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...
Nine Posted December 29, 2023 Share Posted December 29, 2023 I agree to fix help as @error is not discussed there as it should be... “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...
junkew Posted December 31, 2023 Share Posted December 31, 2023 When you use it with value start which would be a number at a certain position it becomes vague to give input as number or as string When you want to replace 1 char at a certain position result seems to be ok but @extended not filled with 1 (would be most logical) ;~ StringReplace ( "string", "searchstring/start", "replacestring" [, occurrence = 0 [, casesense = 0]] ) Local $sBug = StringReplace("001234567892", 2, "a") ConsoleWrite($sBug & " - replacements: " & @extended & " <-- expected 1" & @CRLF) ;~ **** ambiguous *** ;~ unclear what to expect as input is string but could be interpreted as start Local $sBug = StringReplace("001234567892", "2", "a") ConsoleWrite($sBug & " - replacements: " & @extended & " <-- expected ?" & @CRLF) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
water Posted December 31, 2023 Share Posted December 31, 2023 I suggest to replace the syntax description StringReplace ( "string", "searchstring/start", "replacestring" [, occurrence = 0 [, casesense = 0]] ) with StringReplace ( "string", "searchstring"/start, "replacestring" [, occurrence = 0 [, casesense = 0]] ) This makes clear that parameter 2 is either a string to search for or an integer to be used as the starting position. Andreik and Nine 2 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
junkew Posted January 1 Share Posted January 1 And it works by design🙂 If the start method is used the occurrence and casesense parameters are ignored. The function will replace the characters in "string", starting at the requested position, with the characters in "replacestring" - as many characters will be replaced as are in "replacestring". However, if there are not enough characters in "string" for the entire "replacestring" to be inserted an empty string is returned and @error is set to 1. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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