Replacing multiple strings errors

I guess the design of replace for strings is to allow only one pattern because patterns in a string can overlap so it would be ambiguous in what sequence to apply them.
But I have not implemented it so it is just a guess.

If you want to apply patterns sequentially you can do:

reduce(replace, ["A"=>"a", "B"=>"b", "C"=>"c"], init="ABC")

EDIT. Just to clarify what I mean by this ambiguity. The following codes do not produce identical results:

julia> reduce(replace, [1=>10, 10=>20], init=[1,2,3])
3-element Array{Int64,1}:
 20
  2
  3

julia> replace([1,2,3], 1=>10, 10=>20)
3-element Array{Int64,1}:
 10
  2
  3

because in replace([1,2,3], 1=>10, 10=>20) the patterns are not applied sequentially.

8 Likes