前端之家收集整理的这篇文章主要介绍了
牛牛牛!正则阿拉伯数字变中国大写,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
using
System;
using
System.Text.RegularExpressions;
class
Program
{
static
string
Converttochinese(
double
x)
{
string
s=x.ToString(
"#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A"
);
string
d=Regex.Replace(s,
@"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))"
,
"${b}${z}"
);
return
Regex.Replace(d,
"."
,
delegate
(Matchm){
return
"负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟萬億兆京垓秭穰"
[m.Value[0]-
'-'
].ToString();});
}
static
void
Main()
{
Randomr=
new
Random();
for
(
int
i=0;i<10;i++)
{
double
x=r.Next()/100.0;
Console.WriteLine(
"{0,14:N2}:{1}"
,x,Converttochinese(x));
}
}
}