Jump to content

remove every other character


Recommended Posts

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()
Link to comment
Share on other sites

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()
Link to comment
Share on other sites

  • Moderators

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...