Selectively replace multiple instances of a character within a string: Difference between revisions

Added 11l
(Added 11l)
Line 21:
{{Template:Strings}}
<br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V rep = [‘a’ = [1 = ‘A’, 2 = ‘B’, 4 = ‘C’, 5 = ‘D’], ‘b’ = [1 = ‘E’], ‘r’ = [2 = ‘F’]]
 
F trstring(oldstring, repdict)
DefaultDict[Char, Int] seen
V newchars = ‘’
L(c) oldstring
V i = ++seen[c]
newchars ‘’= I c C repdict & i C repdict[c] {repdict[c][i]} E c
R newchars
 
print(‘abracadabra -> ’trstring(‘abracadabra’, rep))</syntaxhighlight>
 
{{out}}
<pre>
abracadabra -> AErBcadCbFD
</pre>
 
=={{header|ALGOL 68}}==
1,463

edits