编写函数进行日期转换;键输入的大写的日期转换成阿拉伯数字的形式

       用winfrom实现的!!!!

Dictionary<char, char> doct = new Dictionary<char, char>();

       private void button1_Click(object sender, EventArgs e)
        {

            StringBuilder str = new StringBuilder();
            string inputStr = textBox1.Text.Trim();
            for (int i = 0; i < inputStr.Length - 1; i++)
            {

                if (doct.ContainsKey(inputStr[i]))
                {
                    str.Append(doct[inputStr[i]]);
                }
                else if (!doct.ContainsKey(inputStr[i]) && inputStr[i] != '十')
                {// &&inputStr[i]!='日
                    str.Append('-');
                }
                else//如果是+
                {
                    if (!doct.ContainsKey(inputStr[i - 1]) && !doct.ContainsKey(inputStr[i + 1]))//二零一二年三月十日       2012-3-10
                    {
                        str.Append("10");
                    }
                    else if (!doct.ContainsKey(inputStr[i - 1]) && doct.ContainsKey(inputStr[i + 1]))////二零一二年三月十三日     2012-3-13
                    {
                        str.Append('1');
                    }

                    else if (doct.ContainsKey(inputStr[i - 1]) && doct.ContainsKey(inputStr[i + 1]))//二零一二年三月二十三日   2012-3-23
                    {
                        //这时不需要翻译
                    }
                    else if (doct.ContainsKey(inputStr[i - 1]) && !doct.ContainsKey(inputStr[i + 1])) //二零一二年三月二十日   2012-3-20
                    {
                        str.Append('0');
                    }

                }

            }
            textBox2.Text = str.ToString();

 

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string str = "一1 二2 三3 四4 五5 六6 七7 八8 九9 零0";
            string[] parts = str.Split(' ');
            for (int i = 0; i < parts.Length; i++)
            {
                doct.Add(parts[i][0],parts[i][1]);
            }
        }

你可能感兴趣的:(日期转换)