StringReplace
["string“, ”a"->"b"]StringReplace
["string", {"$s_1$"->"$sp_1$“, ”$s_2$"->"$sp_2$"}]StringReplace
["string", srules, n]StringReplace
[{"$string_1$“, ”$string_2$", ...}, srules]StringReplace replaces all occurrences of one substring with another:
StringReplace["xyxyxyyyxxxyyxy", "xy" -> "A"]
Multiple replacements can be supplied:
StringReplace["xyzwxyzwxxyzxyzw", {"xyz" -> "A", "w" -> "BCD"}]
Only replace the first 2 occurrences:
StringReplace["xyxyxyyyxxxyyxy", "xy" -> "A", 2]
Also works for multiple rules:
StringReplace["abba", {"a" -> "A", "b" -> "B"}, 2]
StringReplace acts on lists of strings too:
StringReplace[{"xyxyxxy", "yxyxyxxxyyxy"}, "xy" -> "A"]
StringReplace also can be used as an operator:
StringReplace["y" -> "ies"]["city"]