Selectively replace multiple instances of a character within a string: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: Add Ruby) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 21: | Line 21: | ||
{{Template:Strings}} |
{{Template:Strings}} |
||
<br> |
<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}}== |
=={{header|ALGOL 68}}== |