erezlevi Posted January 29, 2008 Share Posted January 29, 2008 if I have the following string: "lskjfdlksjdflkjsdferezlskjflskjdflkdsjferezlksdjflskdjflkdsjerezlksdjflskdjflkjdserez" and I want to get the "erez" out of there an put a space instead, what is the way to do it? I though that stringreplace will help here but " " is less then "erez" in the number of char. so it replaces "erez" with " rez" Link to comment Share on other sites More sharing options...
Richard Robertson Posted January 29, 2008 Share Posted January 29, 2008 That sounds like incorrect behavior. Replacing something with something else should remove the entire entry and replace it. Did you actually get that result? Link to comment Share on other sites More sharing options...
erezlevi Posted January 29, 2008 Author Share Posted January 29, 2008 That sounds like incorrect behavior. Replacing something with something else should remove the entire entry and replace it. Did you actually get that result? yes, and it is because the stringreplace is the count value only gives you this: count [optional] The number of times to replace the searchstring. 0 = all searchstrings will be replaced (default) but not to replace from e to z with " ". Link to comment Share on other sites More sharing options...
erezlevi Posted January 29, 2008 Author Share Posted January 29, 2008 (edited) yes, and it is because the stringreplace is the count value only gives you this: count [optional] The number of times to replace the searchstring. 0 = all searchstrings will be replaced (default) but not to replace from e to z with " ". sorry I was wrong that is not the problem I am facing. the problem is more illustrated in the previous post I made in the first page. can you look there? here is a short version: this is the string: "list bcms skill 107 [1;1H[24;0H[K7[1;1H[0;7mlist bcms skill 107 [0m8[23;0H[0;7m[" $m=string($s) $p1=StringInStr($m,Chr(27)) $p2=StringInStr($m,"H") $p3=($p2-$p1)+1 $p4=StringMid ($m,$p1,$p3) MsgBox (0,"$m before",$m) $m=StringReplace ($m,$p1," ",$p3) StringReplace ( MsgBox (0,"",$p1&$p2 & @CRLF & $p3 & @CRLF & $p4) MsgBox (0,"$m after",$m) FileOpen ("c:\erez.txt",2) FileWrite ("c:\erez.txt",$m) I need to extract everything in this line that start with Chr(27) and end with "H" like this: [1;1H or this: [23;0H. the problem is that with VB script I have the command: Replace(s, Mid(s, InStr(1, s, Chr(27)), InStr(InStr(1, s, Chr(27)), s, "H") - InStr(1, s, Chr(27)) + 1), " ", 1) and with AutoIT the StringReplace does not have border! it only have starting point and replacement string but it does not replace the whole string if the replacment is not equal to the total substring in the first place. how can I use StringRegExpReplace here? Edited January 29, 2008 by erezlevi Link to comment Share on other sites More sharing options...
GEOSoft Posted January 29, 2008 Share Posted January 29, 2008 (edited) $String = "lskjfdlksjdflkjsdferezlskjflskjdflkdsjferezlksdjflskdjflkdsjerezlksdjflskdjflkjdserez" $String = StringReplace($String, "erez", " ") Edited January 29, 2008 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
erezlevi Posted January 29, 2008 Author Share Posted January 29, 2008 $String = "lskjfdlksjdflkjsdferezlskjflskjdflkdsjferezlksdjflskdjflkdsjerezlksdjflskdjflkjdserez"$String = StringReplace($String, "erez", " ")I know I made a mistake when trying to made it easier to understand, look above it is the right scenario. Link to comment Share on other sites More sharing options...
Siao Posted January 29, 2008 Share Posted January 29, 2008 _StringBetween() "be smart, drink your wine" Link to comment Share on other sites More sharing options...
erezlevi Posted January 29, 2008 Author Share Posted January 29, 2008 _StringBetween() ok, no escape from using Array this time. I will have to make an Array and put all the strings i found that start with {esc} and ends with "H" they can be: " [1;1H " "[ VB is like AutoIT but have much more options H" and many more. putting them inside an Array and make a replace string for each and every one of them..... ohhhhr When VB is much better the AutoIT you must say so... sorry. (JON...) Link to comment Share on other sites More sharing options...
GEOSoft Posted January 29, 2008 Share Posted January 29, 2008 ok, no escape from using Array this time. I will have to make an Array and put all the strings i found that start with {esc} and ends with "H" they can be: " [1;1H " "[ VB is like AutoIT but have much more options H" and many more. putting them inside an Array and make a replace string for each and every one of them..... ohhhhr When VB is much better the AutoIT you must say so... sorry. (JON...)Look at _StringBetween() in the UDFs George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Squirrely1 Posted January 29, 2008 Share Posted January 29, 2008 (edited) I don't know what is wrong with this code, StringReplace works everytime it's tried: $z = "lskjfdlksjdflkjsdferezlskjflskjdflkdsjferezlksdjflskdjflkdsjerezlksdjflskdjflkjdserez" ConsoleWrite(@CR & 'Original string length: ' & StringLen($z) & @CR) $x = StringReplace ($z, "erez", " ", 0 ,0) ConsoleWrite("Number of Replacements made: " & @extended & @CR) ConsoleWrite('Final string length: ' & StringLen($x) & @CR) ConsoleWrite('Final string: ' & $x & @CR & @CR) Original string length = 85 Four replacements times four characters = 16 + four space characters = 12 Final length = 73 Edited January 29, 2008 by Squirrely1 Das Häschen benutzt Radar Link to comment Share on other sites More sharing options...
GEOSoft Posted January 29, 2008 Share Posted January 29, 2008 I don't know what is wrong with this code, StringReplace works everytime it's tried: $z = "lskjfdlksjdflkjsdferezlskjflskjdflkdsjferezlksdjflskdjflkdsjerezlksdjflskdjflkjdserez" ConsoleWrite(@CR & 'Original string length: ' & StringLen($z) & @CR) $x = StringReplace ($z, "erez", " ", 0 ,0) ConsoleWrite("Number of Replacements made: " & @extended & @CR) ConsoleWrite('Final string length: ' & StringLen($x) & @CR) ConsoleWrite('Final string: ' & $x & @CR & @CR) Original string length = 85 Four replacements times four characters = 16 + four space characters = 12 Final length = 73 If you go back and read post 4 you will see whats wrong with it. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
erezlevi Posted February 2, 2008 Author Share Posted February 2, 2008 I'v solved the problem, using Array's. Thanks for your help. 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