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 15:36, 5 May 2023
, 1 year agono edit summary
Drkameleon (talk | contribs) (added Arturo) |
No edit summary |
||
Line 139:
std::cout << magic << "\n";
}</syntaxhighlight>
{{out}}
<pre>
AErBcadCbFD
</pre>
=={{header|EMal}}==
<syntaxhighlight lang="emal">
fun transmogrify = text by text input, Map replacements
Map indexes = text%int[]
text result = ""
for each text ch in input do result.append(when(replacements.has(++indexes[ch] + ch), replacements[indexes[ch] + ch], ch)) end
return result
end
writeLine(transmogrify("abracadabra", text%text["1a" => "A", "2a" => "B", "4a" => "C", "5a" => "D", "1b" => "E", "2r" => "F"]))
</syntaxhighlight>
{{out}}
<pre>
|