数字换成大写
代码如下:
using System;
using System.Collections.Generic; using System.Text;
using System.Text.RegularExpressions;
namespace ConvertNumber
{
class Program
{
static void Main(string[] args)
{
GetZWNum(Console.ReadLine());
Console.ReadLine();
}
public static string GetZWNum(string strN)
{
string[] strNum = { "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
int bl = -1;
bool ch = true;
int len = strN.Length;
if (len > 24)
{
Console.WriteLine("您输入的数字过大,无法转换~");
return "";
}
string strResult = "";
string[] strSZ = new string[len];
for (int i = 0; i < len; i++)
{
strSZ[i] = strN.Substring(i, 1);
if (!Regex.IsMatch(strSZ[i], "^[0-9]$"))
{
Console.WriteLine("您输入的数字含有非数字符号~");
return "";
}
if (strSZ[0] == "0" && ch)//检验首位出现零的情况
{
if (i != len - 1 && strSZ[i] == "0" && strSZ[i + 1] != "0")
bl = i;
else
ch = false;
}
}
for (int i = 0; i < len; i++)
{
int num = len - i;
if (strSZ[i] != "0")
{
strResult += strNum[Convert.ToInt32(strSZ[i]) - 1];//将阿拉伯数字转换成中文大写数字
//加上单位
if (num % 4 == 2)
strResult += "拾";
if (num % 4 == 3)
strResult += "佰";
if (num % 4 == 0)
strResult += "仟";
if (num % 4 == 1)
{
if (num / 4 == 1)
strResult += "萬";
if (num / 4 == 2)
strResult += "亿";
if (num / 4 == 3)
strResult += "萬";
if (num / 4 == 4)
strResult += "亿";
if (num / 4 == 5)
strResult += "萬";
}
}
else
{
if (i > bl)
{
if ((i != len - 1 && strSZ[i + 1] != "0" && (num - 1) % 4 !=
0))
{
//此处判断“0”不是出现在末尾,且下一位也不是“0”;
//如 10012332 在此处读法应该为壹仟零壹萬贰仟叁佰叁拾贰,两个零只要读一个零
strResult += "零";
}
if (i != len - 1 && strSZ[i + 1] != "0")
{
switch (num)
{
10002332,“0”出现在万位上就//此处出现的情况是如
应该加上一个“萬”读成壹仟萬零贰仟叁佰叁拾贰
case 5: strResult += "萬";
break;
case 9: strResult += "亿";
break;
case 13: strResult += "萬";
break;
}
}
if (i != len - 1 && strSZ[i + 1] != "0" && (num - 1) % 4 ==
0)
{
//此处出现的情况是如 10002332,“0”出现在万位上就应该加上一个“零”读成壹仟萬零贰仟叁佰叁拾贰
strResult += "零";
}
}
}
}
return strResult;
}
}
}
? - ???? ????
??wen????????????????????????????????????????????????
????????????????
????????????????????????(?)??????????--?????
??????????????????????--??????
?????????????????--??????
(1) ?????????????????"?"???????????:??;???
(2) ??? [figure;veins]
??????:text?article??????????????????????????????????????????????????????????????????????????????"?"??????????????"?"???????????????????????????????????????????????????????"?"?????????????????????
??????????
1????????????????????
2.????????
3????????????????????
4??????????????????????????????????????????????????????a????????????b??????????
5?????????????????
6????????????????
7??????????????????????????
8??????????????????
9?????????????
10???????????????????????????
11??????????????552????????
12???????????
13?????????
14????????????????
15???
16? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????
?????????
??????????
???
1????
??????????????????????????????????????1991?7?????
?????????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
2?
??? [figure;veins]
???????????????棗????????
???????棗???????????????????????????????????????????????
???????棗??????
?????棗???????
??????????棗???????
?????棗???????????????
3????????????????????????????????????????????????????????????????????????????
4???????????????????????????????????????????????????????????? [character]
?????棗?????????????
?????棗???????????
????????棗?????????
????????????????棗??????????
?????????棗??????????
???????
5???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
6??????????????????? ??? [literary composition]
??????????棗???????
????棗????????
????????棗???????????
?????棗???????????
?????棗????????????
7?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
8?????? [virtue]
????????????棗?????????
9???????????????????????????????????????????????????????????????????????????????????????
10.??????????????? [literary talent]
??????????棗???????????
11????????????????????????????????????????????????????????????????????????????????
12????????? [document;classics;verse]
??????棗???????
???????????棗???????
13???????????
[writings;record]????????????????????????????????????????????????????????????????????????????????????
14????????? [natural phenomenon]
???????棗??????????
15????????????????????????????????????????????????
16??????????????? [achievements in culture and education?civilian post]
?????棗???????????
??????
?????棗????????????
????????????????????????????????
17??????????????????????????????????????????????????????????????????????????????????????????????????????????
18????? [articles of decree]
???????????????棗????????
19????????????????????????????????????????????????????????????????????????
20???????????????????????? [literary language]???????????????????????
21???????? [rites]
?????棗??????
22??????(??????)???(?????????)???(???)???(????)??????????????(????)
23????????? [form;appearance]?????(????)???(???????)???(??)
24????????? [music;tune]?????(???)???(???)
25????????????? [study deligently]
??????棗????
??????
26??
???
1???????????? [tatto (the skin)]
?????棗????????????????????
?????棗??????
2???????(?????????)?????(??????????????????????????????????????????????)???(????
???)
3?????? [cover up]
?????????棗??????????
??????????????棗????????
4???????????(?????)???(??????)
5??? [decorate]
?????棗??????
?????
?????棗???????????
??????棗???????
????????棗???????
6??????(????)???(???????)???(???????)???(??)???(???????)??????(??????)???(??????
)???(??????)
7????? [write]?????(??????)???(??????????)??????(???)
???
1?????????????? [magnificent;gorgeous]
????????棗??????
????????????棗??????????
2??????(????)???(?????)???(?????)???(?????)???(??????)???(?????)???(?????)
3.?????? [mild;gentle]?????(?????)
4???? [fine;good]?????(??)???(?????????????)???(?????)
5??????? [disordered]
???????????????棗?????
????????????????????棗????????
???????????????棗??????????
???
1??????????????
2????????
????????????棗?????