Because the "chars" always must be pairs, the function StdErr_Write() is needed to make sure that only "pairs" are specified.
Code: Select all
; ============================================================================================
; | StrReplace(string, chars)
; |
; | Date : 2013 / 12 / 12
; |
; | Author : Holle
; |
; | Syntax: StrReplace("Text", "replace, with, replace, with, ...")
; |
; | Examples: StrReplace("Hello", "H,B,o,a") --> "Bella"
; | StrReplace("Abcde123", "bcd,v,1," A_Space ",23,Cesar") --> "Ave Cesar"
; |
; ============================================================================================
StrReplace(string, chars) {
StringSplit, char, chars, `,
if mod(char0,2)
ExitApp StdErr_Write(A_LineNumber,"This function needs pairs of parameter.","odd number (" strings.MaxIndex() ")")
ParNum := 1
ParNum2 := ParNum +1
while(ParNum < char0) {
with := ParNum +1 , replace := Char%ParNum% , with := Char%with%
StringReplace, string, string, %replace%, %with%, all
ParNum += 2
}
return string
}