According to customer requirements, convert "-11-4""
Using system;
Using system. text;
Using
System. Text. regularexpressions;
Namespace andydateconvert
{
Class dateconvert
{
Private Static dateconvert
M_dateconvert = NULL;
Private char [] strchinese;
Private dateconvert ()
{
Strchinese = new char []
{
'0', 'yi', '2', '3', '4', '5', '6', '7', '8', '9 ', '10'
};
}
Public static dateconvert instance
{
Get
{
If (m_dateconvert =
Null)
M_dateconvert = new
Dateconvert ();
Return m_dateconvert;
}
}
Public String baodate2chinese (string
Strdate)
{
Stringbuilder result = new
Stringbuilder ();
// Judge whether the parameter is correct based on the regular expression
RegEx
Thereg = new RegEx (@ "(D {2} | D {4}) (/|-) (d {1, 2}) (/|-) (d {1, 2 }) ");
If
(Thereg. Match (strdate). length! = 0)
{
//
Save the year, month, and day of the digit date to the character array 'str '.
String [] STR = NULL;
If (strdate. Contains ("-"))
{
STR =
Strdate. Split ('-');
}
Else if
(Strdate. Contains ("/"))
{
STR =
Strdate. Split ('/');
}
//
STR [0] is a year, which converts each character into a corresponding Chinese Character
For (INT I = 0; I <
STR [0]. length; I ++)
{
Result. append (strchinese [Int. parse (STR [0] [I]. tostring ()]);
}
Result. append ("year ");
//
Conversion month
Int month = int. parse (STR [1]);
Int
Mn1 = month/10;
Int Fe2 = month %
10;
If (Mn1> 1)
{
Result. append (strchinese [Mn1]);
}
If (Mn1> 0)
{
Result. append (strchinese [10]);
}
If (Fe2! = 0)
{
Result. append (strchinese [Fe2]);
}
Result. append ("month ");
//
Conversion date
Int day = int. parse (STR [2]);
Int dn1
= Day/10;
Int dn2 = day % 10;
If
(Dn1> 1)
{
Result. append (strchinese [dn1]);
}
If
(Dn1> 0)
{
Result. append (strchinese [10]);
}
If (dn2
! = 0)
{
Result. append (strchinese [dn2]);
}
Result. append ("day ");
}
Else
{
Throw new argumentexception ();
}
Return result. tostring ();
}
Static void main (string [] ARGs)
{
Console. writeline (dateconvert. instance. baodate2chinese ("2007-11-4 "));
Console. writeline (dateconvert. instance. baodate2chinese ("07-11-4 "));
Console. writeline (dateconvert. instance. baodate2chinese ("2007/11/4 "));
Console. writeline (dateconvert. instance. baodate2chinese ("07/11/4 "));
}
}
}