Sign in to follow this  
Followers 0
MrKris7100

Multiple replace

5 posts in this topic

#1 ·  Posted (edited)

Welcome. I'm Pole, and my english is weak so will use the google translator. I have a problem because I would like one command replace letters in the text "abti".
a = %charmap:0,1%
b =
%charmap:0,2%

t = %charmap:0,3%

i = %charmap:0,4%
the result would be %charmap:0,1%%charmap:0,2%%charmap:0,3%%charmap:0,4%

Edited by MrKris7100

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

well, one 'command', that is actually a function :)...the function only replaces characters once, so you don't have to worry about it returning cbc, or aba...actual return will be cba

#include <array.au3>

Global Enum $giReplace_Find, $giReplace_Replace, $giReplace_UBound
Global $aReplace[2][$giReplace_UBound]=[["a","c"],["c","a"]]
Global $string = "abc"

$string = MultiReplace($string,$aReplace)
ConsoleWrite($string & @CRLF)

Func MultiReplace($sCallersString, $aCallersReplace)
    $aString = StringToASCIIArray($sCallersString)
    Local $aString2d[UBound($aString)][2], $sReturn = ""
    For $i = 0 to UBound($aString2d)-1
        $aString2d[$i][0] = Chr($aString[$i])
        $aString2d[$i][1] = False
    Next

    ; Do replaces on chars that have not already been replaced
    For $i = 0 to UBound($aString2d)-1
        If Not $aString2d[$i][1] Then
            For $j = 0 To UBound($aCallersReplace)-1
                If $aString2d[$i][0] = $aCallersReplace[$j][$giReplace_Find] Then
                    $aString2d[$i][0] = $aCallersReplace[$j][$giReplace_Replace]
                    $aString2d[$i][1] = True
                    ExitLoop
                EndIf
            Next
        EndIf
    Next

    ; Convert the array back to a string
    For $i = 0 to UBound($aString2d)-1
        $sReturn &= $aString2d[$i][0]
    Next

    Return $sReturn
EndFunc
Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I edited the my post see him again ...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

changed the string on me, here ya go (not sure if those are actual chars, or literal strings...)  literal strings:

#include <array.au3>

Global Enum $giReplace_Find, $giReplace_Replace, $giReplace_UBound
;~ Global $aReplace[2][$giReplace_UBound]=[["a","c"],["c","a"]]
Global $aReplace[4][$giReplace_UBound]=[["a","%charmap:0,1%"],["b","%charmap:0,2%"],["t","%charmap:0,3%"],["i","%charmap:0,4%"]]

;~ Global $string = "abc"
Global $string = "abti"

$string = MultiReplace($string,$aReplace)
ConsoleWrite($string & @CRLF)

Func MultiReplace($sCallersString, $aCallersReplace)
    $aString = StringToASCIIArray($sCallersString)
    Local $aString2d[UBound($aString)][2], $sReturn = ""
    For $i = 0 to UBound($aString2d)-1
        $aString2d[$i][0] = Chr($aString[$i])
        $aString2d[$i][1] = False
    Next

    ; Do replaces on chars that have not already been replaced
    For $i = 0 to UBound($aString2d)-1
        If Not $aString2d[$i][1] Then
            For $j = 0 To UBound($aCallersReplace)-1
                If $aString2d[$i][0] = $aCallersReplace[$j][$giReplace_Find] Then
                    $aString2d[$i][0] = $aCallersReplace[$j][$giReplace_Replace]
                    $aString2d[$i][1] = True
                    ExitLoop
                EndIf
            Next
        EndIf
    Next

    ; Convert the array back to a string
    For $i = 0 to UBound($aString2d)-1
        $sReturn &= $aString2d[$i][0]
    Next

    Return $sReturn
EndFunc

Notice, that you just have to change the conversion array (line 5), to do any replaces...and any count of replaces

Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

ohh thanks!!!

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