//加到类的定义部分
private static string[] cstr={"零","壹","贰","叁","肆", "伍", "陆","柒","捌","玖"};
private static string[] wstr={"","","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟"};
//数字必须在12位整数以内的字符串
//调用方式如:Label1.Text=ConvertInt("数字字符串");
public string ConvertInt(string str)
{
int len=str.Length;
int i;
string tmpstr,rstr;
rstr="";
for(i=1;i<=len;i++)
{
tmpstr=str.Substring(len-i,1);
rstr=string.Concat(cstr[Int32.Parse(tmpstr)]+wstr[i],rstr);
}
rstr=rstr.Replace("拾零","拾");
rstr=rstr.Replace("零拾","零");
rstr=rstr.Replace("零佰","零");
rstr=rstr.Replace("零仟","零");
rstr=rstr.Replace("零萬","萬");
for(i=1;i<=6;i++)
rstr=rstr.Replace("零零","零");
rstr=rstr.Replace("零萬","零");
rstr=rstr.Replace("零億","億");
rstr=rstr.Replace("零零","零");
rstr+="圆整";
return rstr;
}
private static string[] cstr={"零","壹","贰","叁","肆", "伍", "陆","柒","捌","玖"};
private static string[] wstr={"","","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟"};
//数字必须在12位整数以内的字符串
//调用方式如:Label1.Text=ConvertInt("数字字符串");
public string ConvertInt(string str)
{
int len=str.Length;
int i;
string tmpstr,rstr;
rstr="";
for(i=1;i<=len;i++)
{
tmpstr=str.Substring(len-i,1);
rstr=string.Concat(cstr[Int32.Parse(tmpstr)]+wstr[i],rstr);
}
rstr=rstr.Replace("拾零","拾");
rstr=rstr.Replace("零拾","零");
rstr=rstr.Replace("零佰","零");
rstr=rstr.Replace("零仟","零");
rstr=rstr.Replace("零萬","萬");
for(i=1;i<=6;i++)
rstr=rstr.Replace("零零","零");
rstr=rstr.Replace("零萬","零");
rstr=rstr.Replace("零億","億");
rstr=rstr.Replace("零零","零");
rstr+="圆整";
return rstr;
}
博客展示了一段C#代码,实现将12位以内整数数字字符串转换为中文大写的功能。代码定义了中文数字和单位数组,通过循环和字符串替换操作完成转换,最终添加“圆整”返回结果。
1282

被折叠的 条评论
为什么被折叠?



