class Program { static void Main(string[] args) { //火星文翻译器 string StrKey = "我"; string StrValue = "卧"; Dictionary<char, char> dic = new Dictionary<char, char>(); for (int i = 0; i < StrKey.Length; i++) { char key = StrKey[i]; char value = StrValue[i]; //加入字典 dic[key] = value; } string msg = "我aaaaa"; StringBuilder sb = new StringBuilder(); for (int i = 0; i < msg.Length; i++) { char key = msg[i]; char? value = null; if (dic.ContainsKey(key)) { value = dic[key]; } else { value = key; } sb.Append(value); } string s = sb.ToString(); Console.WriteLine(s); Console.ReadKey(); } }
时间: 2024-10-13 22:25:45