; The original, simple and to the point... SimpleStringMod(_string, _mode="", _chars="", _replCh="") { local rStr ; Defaults If _mode not in Omit,Only,Replace _mode = Omit If _chars = _chars = %A_Space% If _replCh = _replCh = _ Loop Parse, _string { ; Is char in the given list? IfInString _chars, %A_LoopField% { If (_mode = "Only") rStr := rStr A_LoopField Else If (_mode = "Replace") rStr := rStr _replCh } Else { If (_mode = "Omit" or _mode = "Replace") rStr := rStr A_LoopField } } Return rStr } ; A beefed up version, does lot of things, less efficient and readable... StringMod(_string, _mode="", _chars="", _replCh="") { local rStr, char, ascii, o ; Defaults If _mode not in Omit,Only,Replace,Flip,Rot13,Rot47 _mode = Omit If _chars = { If _mode = Rot13 { _chars = 13 } Else If _mode = Rot47 _chars = 47 Else _chars = %A_Space% } If _replCh = _replCh = _ Loop Parse, _string { If (_mode = "Flip") { rStr := A_LoopField rStr } Else If (_mode = "Rot13") { char := Asc(A_LoopField) ; o is 'A' code if it is an uppercase letter, and 'a' code if it is a lowercase letter o := Asc("A") * (Asc("A") <= char && char <= Asc("Z")) + Asc("a") * (Asc("a") <= char && char <= Asc("z")) If (o > 0) { ; Set between 0 and 25, add rotation factor, modulus alphabet size char := Mod(char - o + _chars, 26) ; Transform back to char, upper or lower char := Chr(char + o) } Else { ; Non alphabetic, unchanged char := A_LoopField } rStr := rStr char } Else If (_mode = "Rot47") { char := A_LoopField If char between ! and ~ { char := Asc(A_LoopField) ; Set between 0 and 93, add rotation factor, modulus range size char := Mod(char - 33 + _chars, 94) ; Transform back to char char := Chr(char + 33) } rStr := rStr char } ; Is char in the given list? Else IfInString _chars, %A_LoopField% { If (_mode = "Only") rStr := rStr A_LoopField Else If (_mode = "Replace") rStr := rStr _replCh } Else { If (_mode = "Omit" or _mode = "Replace") rStr := rStr A_LoopField } } Return rStr } ; Run test code only if the file is ran standalone If (A_ScriptName = "StringMod.ahk") { str = The name of the variable whose contents will be analyzed. filename = This?Is?\A:/<"Valid"File>*Name?.txt invalidFilenameCharacters=\/:*?"<>| r = | r := r StringMod(str, "OMIT", " ") "|`n|" r := r StringMod(str, "Omit", "aeiouy") "|`n|" r := r StringMod(str, "only", " ") "|`n|" r := r StringMod(str, "Only", "aeiouy ") "|`n" r := r StringMod(str, "RePlAcE", " ") "|`n|" r := r StringMod(str, "Replace", "aeiouy", "$") "|`n|" r := r StringMod(str, "Flip") "|`n|" r := r StringMod(str, "Rot13") "|`n|" r := r StringMod(str, "Rot13", 11) "|`n|" r := r StringMod(str, "Rot47") "|`n|" r := r StringMod(str, "Rot47", 33) "|`n|" r := r StringMod(filename, "Omit", invalidFilenameCharacters) "|`n|" r := r StringMod(filename, "Replace", invalidFilenameCharacters) "|`n|" r := r StringMod(filename, "Replace", invalidFilenameCharacters, " Fun ") "|`n" MsgBox %r% a1 := StringMod(str, "Rot13") b1 := StringMod(a1, "Rot13") a2 := StringMod(str, "Rot13", 7) b2 := StringMod(a2, "Rot13", 26-7) MsgBox Rot13:`n%str%`n%a1%`n%b1%`n%a2%`n%b2% a1 := StringMod(str, "Rot47") b1 := StringMod(a1, "Rot47") a2 := StringMod(str, "Rot47", 13) b2 := StringMod(a2, "Rot47", 94-13) MsgBox Rot47:`n%str%`n%a1%`n%b1%`n%a2%`n%b2% r = | r := r SimpleStringMod(str, "OMIT", " ") "|`n|" r := r SimpleStringMod(str, "Omit", "aeiouy") "|`n|" r := r SimpleStringMod(str, "only", " ") "|`n|" r := r SimpleStringMod(str, "Only", "aeiouy ") "|`n" r := r SimpleStringMod(str, "RePlAcE", " ") "|`n|" r := r SimpleStringMod(str, "Replace", "aeiouy", "$") "|`n|" r := r SimpleStringMod(filename, "Omit", invalidFilenameCharacters) "|`n|" r := r SimpleStringMod(filename, "Replace", invalidFilenameCharacters) "|`n|" r := r SimpleStringMod(filename, "Replace", invalidFilenameCharacters, " Fun ") "|`n" MsgBox %r% }