WeMartiansAreFriendly Posted January 9, 2007 Share Posted January 9, 2007 (edited) i need to replace characters in a string lets say 1 is added every 3 characters, and the string is abcdefg so it becomes abc1def1g, what i want to do now is remove those extra characters and revert it back to abcdefg, is they possible? Local $text ='', $realstring = 'abcdefg', $string = 'abc1def1g', $Step = 3 For $x = 1 to StringLen($string) Step $Step $text = StringMid($string, $x, $step) & StringMid($string, $x, -$step); StringRegExpReplace($string,'.*{3}','') $string = $text Next ConsoleWrite($realstring&@lf&$string) Edited January 9, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted January 9, 2007 Author Share Posted January 9, 2007 (edited) i havent got much success with this code either, not much difference but still. Local $text ='', $realstring = 'abcdefg', $string = 'abc1def1g', $Step = 3 For $x = 1 to StringLen($string) Step $Step $text = StringMid($string, 1, $step) & StringMid($string, $x, -$step); StringRegExpReplace($string,'.*{3}','') $string = $text Next ConsoleWrite('r; '&$realstring&@lf&'o; '&$string) Edited January 9, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Danny35d Posted January 9, 2007 Share Posted January 9, 2007 If all you want is to remove 1 then use StringReplace.Local $text ='', $realstring = 'abcdefg', $string = 'abc1def1g', $Step = 3 ConsoleWrite('r; '&$realstring&@lf&'o; '& StringReplace($string, '1', '') & @CRLF) AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted January 9, 2007 Author Share Posted January 9, 2007 i need to replace every nth characters. (nth can be 3 or whatever) Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 9, 2007 Moderators Share Posted January 9, 2007 Your example $Step shows 3, but it's actually the 4th char. Try this:Local $realstring = 'abcdefg', $string = 'abc1def1g', $Step = 4 MsgBox(0, 'Info', 'Original string: ' & $realstring & @CR & 'Altered string: ' & _ReplaceChar($string, $Step)) Func _ReplaceChar($sString, $nReplace = 1) Local $sText = '' For $iCC = 1 To StringLen($sString) If Mod($iCC, $nReplace) Then $sText &= StringMid($sString, $iCC, 1) Next If $sText Then Return $sText Return SetError(1, 0, 0) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted January 9, 2007 Author Share Posted January 9, 2007 hey, thanks SmOkEn, it worked great Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() 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