您的位置:首页 > 编程语言 > C#

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

2017-12-10 20:05 204 查看
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();

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c#
相关文章推荐