Convert date to Chinese capital number

Source: Internet
Author: User

To write a small method of converting the date, although very short, but need to consider the things are quite a bit, record.

 /// <summary>    ///Convert a date to Chinese capital///Example: 19,957/// </summary>     Public classChinesenumberhelper {Staticdictionary<int,string> _thenumofchinesecapital =Newdictionary<int,string>()         {            {0,"0"},            {1,"a"},            {2,"two"},            {3,"three"},            {4,"Four"},            {5,"Five"},            {6,"Six"},            {7,"Seven"},            {8,"Eight"},            {9,"Nine"},            {Ten,"10"}        };  Public Static stringConvertostring (ObjectNumber , Numbertype numtype) {            varinput =convert.tostring (number); intValidateint; if(string. Isnullorwhitespace (input) | | !int. TryParse (Input, outvalidateint)) Throw NewArgumentException (" Number"); if(Validateint = =0)                Throw NewArgumentException (" Number"); //more verification If it is the date of the month and day of input            if(Numtype = = Numbertype.day | | numtype = = numbertype.day) && input. Length = =2) Input= input. TrimStart ('0'); StringBuilder OutPut=NewStringBuilder (); Switch(numtype) { Casenumbertype.year: for(inti =0; I < input. Length; i++)                    {                        varIntval =Convert.ToInt32 (Input[i].                        ToString ());                    Output.append (_thenumofchinesecapital[intval]); }                     Break;  CaseNumbertype.moth: CaseNumbertype.day:if(Validateint <Ten) {output.append (_thenumofchinesecapital[convert.toint32 (input[0].                    ToString ())]); }                    Else if(Validateint = =Ten) {output.append (_thenumofchinesecapital[validateint]); }                    Else                    {                        if(Validateint > +) Output.append (_thenumofchinesecapital[convert.toint32 (input[0].                        ToString ())]); Output.append (_thenumofchinesecapital[Ten]); if(input[1] !='0') Output.append (_thenumofchinesecapital[convert.toint32 (input[1].                    ToString ())]); }                     Break; }            returnoutput.tostring (); }    }     Public enumnumbertype {year, moth, day}

Convert date to Chinese capital number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.