C# 字典(dictionary)练习,小写数字转大写

来源:互联网 发布:淘宝网店装修模板代码 编辑:程序博客网 时间:2024/05/29 03:24


using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _10键值对集合练习{    class Program    {        static void Main(string[] args)        {            string str = "1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖 0零";            //输入小写---->大写形式            Dictionary<char, char> dic = new Dictionary<char, char>();            string[] strNew = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);            //给dic集合添加数据            for (int i = 0; i < strNew.Length; i++)            {                dic.Add(strNew[i][0], strNew[i][1]);            }            Console.WriteLine("请输入小写,我们将转换成大写");            string input = Console.ReadLine();            //123123  乱七八糟abc            for (int i = 0; i < input.Length; i++)            {                if (dic.ContainsKey(input[i]))                {                    Console.Write(dic[input[i]]);                }                else                {                    Console.Write(input[i]);                }            }            Console.ReadKey();        }    }}



原创粉丝点击