Sign in to follow this  
Followers 0
WeMartiansAreFriendly

remove every other character

6 posts in this topic

#1 ·  Posted (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 by mrRevoked

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by mrRevoked

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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


[center]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.[/center]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0