$a=array("o" => "l", "l" => "o");
$b=strtr("ololo",$a);
using System;
using System.Text;
using System.Collections.Generic;
class Program
{
public static void Main(string[] args)
{
var repl = new Dictionary<char, char> { {'o', 'l'}, {'l','o'} };
var src = "ololo";
Console.WriteLine("Source string: " + src + "; changed string: " + src.Strtr(repl));
Console.ReadKey();
}
}
public static class StringExt
{
public static string Strtr(this string src, Dictionary<char, char> replacePairs) {
var sb = new StringBuilder();
foreach (char c in src) {
if(replacePairs.ContainsKey(c)) {
sb.Append(replacePairs[c]);
} else {
sb.Append(c);
}
}
return sb.ToString();
}
}