将大写日期转成阿拉伯数字类型的

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 练习7编写函数进行日期转换2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Dictionary<char,char> dict = new Dictionary<char,char>();
        private void button1_Click(object sender, EventArgs e)
        {
            string ri = "零0 一1 二2 三3 四4 五5 六6 七7 八8 九9";
            string[] nianyueri=ri.Split(' ');
            for (int i = 0; i < nianyueri.Length; i++) {
                dict.Add(nianyueri[i][0],nianyueri[i][1]);
            }
            StringBuilder sb=new StringBuilder();
            string shuru = richTextBox1.Text;
            
            for (int i = 0; i < shuru.Length; i++) {
                if (dict.ContainsKey(shuru[i])) {
                    sb.Append(dict[shuru[i]]);
                }
                else if (!dict.ContainsKey(shuru[i]) && shuru[i] != '十'&&shuru[i]!='日')
                {
                    sb.Append('-');
                }
                else if(shuru[i] == '十'){
                    if (!dict.ContainsKey(shuru[i + 1]) && !dict.ContainsKey(shuru[i - 1])) {
                        sb.Append("10");
                    }
                    else if (dict.ContainsKey(shuru[i - 1]) && !dict.ContainsKey(shuru[i + 1])) {
                        sb.Append("0");
                    }
                    else if (!dict.ContainsKey(shuru[i - 1]) && dict.ContainsKey(shuru[i + 1]))
                    {
                        sb.Append("1");
                    }
                    else if (dict.ContainsKey(shuru[i - 1]) && dict.ContainsKey(shuru[i + 1]))
                    {
                        sb.Append("");
                    }
                }
            }
            richTextBox2.Text = sb.ToString();
        }
    }
}

 

posted on 2012-09-12 20:40  gongth_12  阅读(172)  评论(0编辑  收藏  举报

导航