给定字符串"1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖",输入对应的数字,输出对应的大写

#region 给定字符串"1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖",输入对应的数字,输出对应的大写
            string str = "1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖";
            //做一个字典
            Dictionary<char, char> dic = new Dictionary<char, char>();
            string[] strNumber = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < strNumber.Length; i++)
            {
                //判断字典里面的键和值   是否存在
                if (!dic.ContainsKey(strNumber[i][0]))//因为键不能重复,每一次添加键和值的情况下,需要判断键是否已经存在   
                {
                    dic.Add(strNumber[i][0], strNumber[i][1]);//输出每一项的键和值

                }
            }

            Console.WriteLine("请输入数字");
            string txt = Console.ReadLine();
            for (int i = 0; i < txt.Length; i++)
            {
                if (dic.ContainsKey(txt[i]))//判断字典里面有没有这个字符
                {
                    Console.Write(dic[txt[i]]);//Console.Write输出不换行  dic[txt[i]]代表键txt[i]对应的值
                }
                else
                {
                    Console.Write(txt[i]);

                }
                Console.ReadKey();
                #endregion

猜你喜欢

转载自blog.csdn.net/nsjlive/article/details/81137447