Selectively replace multiple instances of a character within a string: Difference between revisions
Selectively replace multiple instances of a character within a string (view source)
Revision as of 02:48, 1 June 2022
, 2 years ago→{{header|Julia}}
Line 91:
rep = Dict('a' => Dict(1 => 'A', 2 => 'B', 4 => 'C', 5 => 'D'), 'b' => Dict(1 => 'E'), 'r' => Dict(2 => 'F'))
function trstring(
seen, newchars = Dict{Char, Int}(), Char[]
for c in
i = get!(seen, c, 1)
push!(newchars, haskey(repdict, c) && haskey(repdict[c], i) ? repdict[c][i] : c)
|