I just found that replace
could be used to replace two bits of a vector as in
replace([1, 2, 1, 3], 1=>0, 2=>4)
Where the replacements are defined using Pair
.
I tried that with a string instead of an integer vector, but that seems to fail.
replace("aabbccdd","a"=>"y","c"=>"z")
ERROR: MethodError: no method matching replace(::String, ::Pair{String, String}, ::Pair{String, String})
Closest candidates are:
replace(::AbstractString, ::Pair, ::Pair) at set.jl:613
replace(::Any, ::Pair…; count) at set.jl:555
replace(::Union{Function, Type}, ::Pair, ::Pair; count) at set.jl:612
…
Stacktrace:
[1] replace(a::String, b::Pair{String, String}, c::Pair{String, String})
@ Base .\set.jl:613
[2] top-level scope
@ REPL[93]:1
Is there a specific reason for this to not be implemented / available / authorized ?
The obvious alternative would be replace(replace("aabbccdd","a"=>"y"),"c"=>"z")
, but it does not feel quit clean.