The number of read texts is converted in English.

Source: Internet
Author: User

Some days ago, my friend told me that I had nothing to do. A simple implementation. I don't want to change the English words. Code writing is a bit redundant, but the function is still implemented. However, only four digits are allowed.

Namespace CountNum
{
Class Program
{

Static void Main (string [] args)
{

Dictionary <int, string> dicGeEnglishGeWei = GetGeWei ();
Dictionary <int, string> dicgetengishshiwei = GetShiWei ();
Dictionary <int, string> dicGetDuble = GetDubleRead ();
// Read numeric text
String [] textNums = File. ReadAllLines ("1.txt", Encoding. UTF8 );
String [] saveTestEnglish = new string [textNums. Length];
For (int I = 0; I <textNums. Length; I ++)
{
Match match = Regex. Match (textNums [I], @ "\ d [1-9]");
// Int number = int. Parse (textNums [I]);
String number = textNums [I];
If (match. Success)
{

Switch (number. Length)
{

Case 1:
// Single-digit English Reading
Int ge = int. Parse (number );
SaveTestEnglish [I] = dicGeEnglishGeWei [ge];
Break;
Case 2:
If (number [0] = '1 ')
{
Int shi = int. Parse (number );
SaveTestEnglish [I] = dicGetDuble [shi];
}
Else
{
SaveTestEnglish [I] = dicgetengishshiwei [SubS (number)] + dicgeengishgewei [SubS (int. Parse (number)-1). ToString ()];
}
Break;
Case 3:
If (number [1] = '1 ')
{
SaveTestEnglish [I] = dicGeEnglishGeWei [SubS (number)] + "hunred and" + dicGetDuble [int. Parse (number. Substring (1)];
}
Else
{
SaveTestEnglish [I] = dicGeEnglishGeWei [SubS (number)] + "hunred and" + dicGetEnglishShiWei [SubS (number. substring (1)] + dicGeEnglishGeWei [SubS (number. substring (2)];
}
Break;
Case 4:
If (number [2] = '1 ')
{
SaveTestEnglish [I] = dicGeEnglishGeWei [SubS (number)] + "thousand" + dicGeEnglishGeWei [SubS (number. substring (1)] + "hunred and" + dicGetDuble [int. parse (number. substring (2)];
}
Else
{
SaveTestEnglish [I] = dicGeEnglishGeWei [SubS (number)] + "thousand" + dicGeEnglishGeWei [SubS (number. substring (1)] + "hunred and" + dicGetEnglishShiWei [SubS (number. substring (2)] + dicGeEnglishGeWei [SubS (number. substring (3)];
}
Break;
Default:
Break;
}


}
Else
{
SaveTestEnglish [I] = "Error ";
}


}
For (int j = 0; j <saveTestEnglish. Length; j ++)
{
Console. WriteLine (saveTestEnglish [j]);
}
Console. Read ();

}
/// <Summary>
/// Number of truncated digits
/// </Summary>
/// <Param name = "num"> </param>
/// <Returns> </returns>
Static int SubS (string num)
{
Int danwei = 0;
Danwei = int. Parse (num. Substring (0, 1 ));

Return danwei;
}
/// <Summary>
/// Return the English corresponding to a single digit
/// </Summary>
/// <Returns> </returns>
Static Dictionary <int, string> GetGeWei ()
{
# Region single-digit dictionary
Dictionary <int, string> dicSingle = new Dictionary <int, string> ();
DicSingle. Add (1, "one ");
DicSingle. Add (2, "two ");
DicSingle. Add (3, "three ");
DicSingle. Add (4, "four ");
DicSingle. Add (5, "five ");
DicSingle. Add (6, "six ");
DicSingle. Add (7, "seven ");
DicSingle. Add (8, "eight ");
DicSingle. Add (9, "ine ");
DicSingle. Add (0 ,"");
# Endregion
Return dicSingle;
}

Static Dictionary <int, string> GetShiWei ()
{
# Region single-digit dictionary
Dictionary <int, string> dicSingle = new Dictionary <int, string> ();
DicSingle. Add (1, "ten ");
DicSingle. Add (2, "twenty ");
DicSingle. Add (3, "thirty ");
DicSingle. Add (4, "forty ");
DicSingle. Add (5, "ty ");
DicSingle. Add (6, "sixty ");
DicSingle. Add (7, "seventy ");
DicSingle. Add (8, "eighty ");
DicSingle. Add (9, "ninty ");
DicSingle. Add (0 ,"");
# Endregion
Return dicSingle;
}

Static Dictionary <int, string> GetDubleRead ()
{
# Region single-digit dictionary
Dictionary <int, string> dicSingle = new Dictionary <int, string> ();
DicSingle. Add (10, "ten ");
DicSingle. Add (11, "eleven ");
DicSingle. Add (13, "thirsteen ");
DicSingle. Add (14, "fourteen ");
DicSingle. Add (15, "fifteen ");
DicSingle. Add (16, "sixteen ");
DicSingle. Add (17, "seventeen ");
DicSingle. Add (18, "eighteen ");
DicSingle. Add (19, "nineteen ");
DicSingle. Add (12, "twelve ");
# Endregion
Return dicSingle;
}
}
}

This article from the "life pursuit" blog, please be sure to keep this source http://hacjj.blog.51cto.com/3843027/1291919

Related Article

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.