MrKris7100 Posted November 22, 2013 Share Posted November 22, 2013 (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 November 22, 2013 by MrKris7100 Link to comment Share on other sites More sharing options...
jdelaney Posted November 22, 2013 Share Posted November 22, 2013 (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 expandcollapse popup#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 November 22, 2013 by jdelaney MrKris7100 1 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. Link to comment Share on other sites More sharing options...
MrKris7100 Posted November 22, 2013 Author Share Posted November 22, 2013 I edited the my post see him again ... Link to comment Share on other sites More sharing options...
jdelaney Posted November 22, 2013 Share Posted November 22, 2013 (edited) changed the string on me, here ya go (not sure if those are actual chars, or literal strings...) literal strings: expandcollapse popup#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 November 22, 2013 by jdelaney MrKris7100 1 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. Link to comment Share on other sites More sharing options...
MrKris7100 Posted November 22, 2013 Author Share Posted November 22, 2013 ohh thanks!!! 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