Jump to content

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

no edit summary
(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>
224

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.