Opened 17 years ago
Closed 17 years ago
#95 closed Bug (Fixed)
StringReplace doesn't recognize some number types as not strings
Reported by: | PsaltyDS | Owned by: | Jpm |
---|---|---|---|
Milestone: | 3.2.11.1 | Component: | AutoIt |
Version: | 3.2.10.0 | Severity: | |
Keywords: | Cc: |
Description
Reported in General Support topic #63374 by jennico.
Tested in 3.2.10.0 and 3.2.11.0 with this:
$sString = "0123" $a = 1 + 1 ConsoleWrite("Debug: $a = " & $a & " type = " & VarGetType($a) & " IsInt($a) = " & IsInt($a) & @LF) $sString_a = StringReplace($sString, $a, "x") ConsoleWrite("Debug: $sString_a = " & $sString_a & @LF) $b = Sqrt(4) ConsoleWrite("Debug: $a = " & $b & " type = " & VarGetType($b) & " IsInt($b) = " & IsInt($b) & @LF) $sString_b = StringReplace($sString, $b, "x") ConsoleWrite("Debug: $sString_b = " & $sString_b & @LF)
Output is:
>Running:(3.2.11.0):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_2.au3" Debug: $a = 2 type = Int32 IsInt($a) = 1 Debug: $sString_a = 0x23 Debug: $a = 2 type = Double IsInt($b) = 1 Debug: $sString_b = 01x3 +>08:37:25 AutoIT3.exe ended.rc:0
With 2 as an INT32 it works correctly, but the DOUBLE causes it to switch to a string-type replace.
Attachments (0)
Change History (4)
comment:1 Changed 17 years ago by Valik
comment:2 follow-up: ↓ 3 Changed 17 years ago by PsaltyDS
Per the help file under StringReplace() about the second parameter:
"searchstring -- The substring to search for or the character position to start the replacement"
If the param is a string, it should find the string and replace it. If the param is a number, it should replace at that 1-based character position. The issue is that the number TYPE is critical. It correctly distinguishes between a string "2" and an INT32 2. But if passed a DOUBLE (float) 2, it mis-interprets as a string.
comment:3 in reply to: ↑ 2 Changed 17 years ago by Valik
Replying to PsaltyDS:
Per the help file under StringReplace() about the second parameter:
"searchstring -- The substring to search for or the character position to start the replacement"
If the param is a string, it should find the string and replace it. If the param is a number, it should replace at that 1-based character position. The issue is that the number TYPE is critical. It correctly distinguishes between a string "2" and an INT32 2. But if passed a DOUBLE (float) 2, it mis-interprets as a string.
This is why you should *always* show your expected output and explain why you expect the output. Quite simply, I did not know StringReplace() could take a numeric parameter and do this. I never thought it would, either, as it doesn't make much sense to me to overload a parameter for this purpose.
comment:4 Changed 17 years ago by Jpm
- Milestone set to 3.2.11.1
- Owner set to Jpm
- Resolution set to fixed
- Status changed from new to closed
Fixed in version: 3.2.11.1
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
I think your report is backwards? The double output is correct. The string "2" in the original string "0123" is replaced with "x" producing "01x3". However, when int 2 is passed in, then the "1" is replaced producing "0x23" which is wrong.
I also don't understand what you mean by "string type replace". It's a string function, what do you expect?