Convert the digital date "2007-11-4" to the Chinese date "November 4, 2007".
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 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine ', ' Ten '
};
}
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 ();
//Based on regular expressions to determine whether the parameters are correct
regex thereg = new Regex (D{2}|d{4}) (/|-) (d{1,2}) (/|-) (d {1,2}) ");
if (Thereg.match (strdate). Length!= 0)
{
//Saves the date of a number to the character array str
string[] str = NULL;
if (Strdate.contains ("-"))
{
str = strdate.split ('-');
}
Else if (strdate.contains ("/"))
{
str = strdate.split ('/');
}
//str[0] in the year, converts its individual characters to the corresponding kanji
for (int i = 0; i < str[0]. Length; i++)
{
Result. Append (Strchinese[int. Parse (Str[0][i]. ToString ())]);
}
result. Append ("year");
//Convert month
int month = Int. Parse (str[1]);
int MN1 = MONTH/10;
int MN2 = month% 10;
if (MN1 > 1)
{
result. Append (Strchinese[mn1]);
}
if (MN1 > 0)
{
result. Append (strchinese[10]);
}
if (MN2!= 0)
{
result. Append (Strchinese[mn2]);
}
result. Append ("month");
//Convert Day
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"));
}
}
}