jennico Posted February 1, 2008 Share Posted February 1, 2008 (edited) hi,took me an hour to finally find the error in my script.....let's say, $a="1253000011111"now i perform $a=StringReplace($a,5,"x"), because i want to replace the "5" in $a with "x".but the result is: $a="1253x00011111" instead of $a="12x3000011111", what i expected.(in fact, my script line is much more complicated, i just simplified it here.)so, is there a trick to make the function work in my way ?the helpfile says:The substring to search for or the character position to start the replacement.can i precisize this or do i have to make a workaround by splitting the string ?and for the future: please update the logic of this function to disambiguate it.thxj. Edited February 1, 2008 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 1, 2008 Share Posted February 1, 2008 It works fine for me. I suspect the problem is with your sig...OS: Win.XP.SP2 AutIt Version: 3.2.8.1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jennico Posted February 1, 2008 Author Share Posted February 1, 2008 (edited) well, maybe i simplified my code too much. i have several algebraic functions in it. let me say it more basically: what result would you expect: $a=StringReplace("1253000011111",5,"x") ? both results, $a="12x3000011111" and $a="1253x00011111" would be correct in the same way. how can you drive the function to the one way or to the other ? this is ambiguous and should be clarified, i think. j. edit: the function has not changed from 3.2.8.1 to 3.2.10.0 and i can't work with the new version because too many bugs. but this is not the solution. Edited February 1, 2008 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
weaponx Posted February 1, 2008 Share Posted February 1, 2008 (edited) well, maybe i simplified my code too much. i have several algebraic functions in it. let me say it more basically:what result would you expect:$a=StringReplace("1253000011111",5,"x") ?both results, $a="12x3000011111" and $a="1253x00011111" would be correct in the same way.how can you drive the function to the one way or to the other ?this is ambiguous and should be clarified, i think.j.edit: the function has not changed from 3.2.8.1 to 3.2.10.0 and i can't work with the new version because too many bugs. but this is not the solution.You need to quote the number 5 in the StringReplace call.Straight from the help file...searchstring - The substring to search for or the character position to start the replacement. Edited February 1, 2008 by weaponx Link to comment Share on other sites More sharing options...
smashly Posted February 1, 2008 Share Posted February 1, 2008 (edited) what result would you expect: $a=StringReplace("1253000011111",5,"x") ? I'd expect $a="12x3000011111" Since your telling StringReplace to look for a string in a string and replace it. So your search string is 5 .. There is a 5 in the string to be searched .. It replaces the 5 with x .. So it's doing exactly what it's meant to. But if I wanted to go by position 5 instead of the search string 5 then I would use$a="1253000011111" $a=StringReplace($a, 5, "x", 1) ConsoleWrite($a & @LF) ; 1253x00011111 Cheers Edit: I didn't use "" around my 5 either and it works. Edited February 1, 2008 by smashly Link to comment Share on other sites More sharing options...
weaponx Posted February 1, 2008 Share Posted February 1, 2008 Different version perhaps, doesn't matter. Just wrap the search string in quotes. Link to comment Share on other sites More sharing options...
Siao Posted February 1, 2008 Share Posted February 1, 2008 $a=StringReplace("1253000011111",5,"x") ?I'd expect $a="12x3000011111"I don't know why would you expect to replace a substring when you don't actually specify any substring.There are strings and there are numbers.Substring being the string type, and position being the number type which makes sense. "be smart, drink your wine" Link to comment Share on other sites More sharing options...
smashly Posted February 1, 2008 Share Posted February 1, 2008 I thought it would be a case that if you wanted to search for a string the you'd put "" around your search string (to let it know it's a string).. If you wanted to do it by position then use a number with no "" around it (so it knows to replace at a position). But it doesn't seem to be the case Side note: I'm using Autoit 3.2.10.0 and 3.2.11.0 beta. Link to comment Share on other sites More sharing options...
jennico Posted February 1, 2008 Author Share Posted February 1, 2008 well, okay then: all you say is right.... but......: this is my line: $Zukunft="535000000000000xx" For $i=4 To 21 If $i=11 Then $i=18 $Zukunft=StringReplace($Zukunft,$i+5*($i=9 Or $i=10)-9*($i>17),1) next this is a number: $i+5*($i=9 Or $i=10)-9*($i>17). not a string ! i also tried Number($i+5*($i=9 Or $i=10)-9*($i>17)). same problem. but instead of replacing the position, to my surprise the function replaces the searchstring. j. Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
BrettF Posted February 1, 2008 Share Posted February 1, 2008 String () Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
randallc Posted February 1, 2008 Share Posted February 1, 2008 Hi, You have to get it from an automatic float after calculation, to integer for this function to work; $Zukunft = StringReplace($Zukunft,Int($i + 5 * ($i = 9 Or $i = 10) - 9 * ($i > 17)), 1)Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
jennico Posted February 1, 2008 Author Share Posted February 1, 2008 You have to get it from an automatic float after calculation, to integer for this function to work;CODE: AutoIt$Zukunft = StringReplace($Zukunft,Int($i + 5 * ($i = 9 Or $i = 10) - 9 * ($i > 17)), 1)Best, Randallyes ! that's it ! i did not think of "Int()", i only tried "Number()", which did not work. i could not imagine that the result is a float although it seems integer.thank you indeed, randallc, you helped a lot.j. Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 1, 2008 Share Posted February 1, 2008 (edited) i did not think of "Int()", i only tried "Number()", which did not work. i could not imagine that the result is a float although it seems integer. It's appears to be a variable typing thang: $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) Inside it's little C++ binary heart, StringReplace must be checking the type with something that doesn't recognize a Double (float) as a number/integer/whatever-its-looking-for. P.S. Added a Bug Trak, ticket #95. Edited February 1, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jennico Posted February 1, 2008 Author Share Posted February 1, 2008 (edited) i see two mini-problems deep inside stringreplace's little heart: 1. $i + 5 * ($i = 9 Or $i = 10) - 9 * ($i > 17) is definitely an arithmetic operation (furthermore results in an integer) so stringreplace should not be able to interprete the result as a string. 2. Number() should clarify the type of variable, but does not. on the other hand, Int() works fine, so thanks to you all. j. Edited February 1, 2008 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 1, 2008 Share Posted February 1, 2008 (edited) i see two mini-problems deep inside stringreplace's little heart: 1. $i + 5 * ($i = 9 Or $i = 10) - 9 * ($i > 17) is definitely an arithmetic operation (furthermore results in an integer) so stringreplace should not be able to interprete the result as a string. 2. Number() should clarify the type of variable, but does not. on the other hand, Int() works fine, so thanks to you all. j. You are using booleans as numbers. Bad idea. Note the changing types of $x: $i = 2 $x = ($i = 9 Or $i = 10) ConsoleWrite("Debug: $x = " & $x & " Type = " & VarGetType($x) & @LF) $x = ($i > 17) ConsoleWrite("Debug: $x = " & $x & " Type = " & VarGetType($x) & @LF) $x = $i + 5 * ($i = 9 Or $i = 10) - 9 * ($i > 17) ConsoleWrite("Debug: $x = " & $x & " Type = " & VarGetType($x) & @LF) Don't lurk too far into AutoIt variable typing -- Here be dragons! Edited February 1, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
jennico Posted February 1, 2008 Author Share Posted February 1, 2008 or, to say it with the Pretenders: "it's a thin line between number and string...." Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 3, 2008 Share Posted February 3, 2008 JPM fixed the original problem for 3.2.11.1 Beta. See Bug Trac #95. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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