实在没有什么好讲的,就是一个方法,大家拿去用吧
using system;
namespace test.com
{
/// <summary>
/// 功能:字符串处理函数集
/// </summary>
public class dealstring
{
#region 私有成员
/// <summary>
/// 输入字符串
/// </summary>
private string inputstring=null;
/// <summary>
/// 输出字符串
/// </summary>
private string outstring=null;
/// <summary>
/// 提示信息
/// </summary>
private string notemessage=null;
#endregion
#region 公共属性
/// <summary>
/// 输入字符串
/// </summary>
public string inputstring
{
get{return inputstring;}
set{inputstring=value;}
}
/// <summary>
/// 输出字符串
/// </summary>
public string outstring
{
get{return outstring;}
set{outstring=value;}
}
/// <summary>
/// 提示信息
/// </summary>
public string notemessage
{
get{return notemessage;}
set{notemessage=value;}
}
#endregion
#region 构造函数
public dealstring()
{
//
// todo: 在此处添加构造函数逻辑
//
}
#endregion
#region 公共方法
public void converttochinesenum()
{
string numlist="零壹贰叁肆伍陆柒捌玖";
string rmblist = "分角元拾佰仟万拾佰仟亿拾佰仟万";
double number=0;
string tempoutstring=null;
try
{
number=double.parse(this.inputstring);
}
catch
{
this.notemessage="传入参数非数字!";
return;
}
if(number>9999999999999.99)
this.notemessage="超出范围的人民币值";
//将小数转化为整数字符串
string tempnumberstring=convert.toint64(number*100).tostring();
int tempnmberlength=tempnumberstring.length;
int i=0;
while(i<tempnmberlength)
{
int onenumber=int32.parse(tempnumberstring.substring(i,1));
string onenumberchar=numlist.substring(onenumber,1);
string onenumberunit=rmblist.substring(tempnmberlength-i-1,1);
if(onenumberchar!="零")
tempoutstring+=onenumberchar+onenumberunit;
else
{
if(onenumberunit=="亿"||onenumberunit=="万"||onenumberunit=="元"||onenumberunit=="零")
{
while (tempoutstring.endswith("零"))
{
tempoutstring=tempoutstring.substring(0,tempoutstring.length-1);
}
}
if(onenumberunit=="亿"||(onenumberunit=="万"&&!tempoutstring.endswith("亿"))||onenumberunit=="元")
{
tempoutstring+=onenumberunit;
}
else
{
bool tempend=tempoutstring.endswith("亿");
bool zeroend=tempoutstring.endswith("零");
if(tempoutstring.length>1)
{
bool zerostart=tempoutstring.substring(tempoutstring.length-2,2).startswith("零");
if(!zeroend&&(zerostart||!tempend))
tempoutstring+=onenumberchar;
}
else
{
if(!zeroend&&!tempend)
tempoutstring+=onenumberchar;
}
}
}
i+=1;
}
while (tempoutstring.endswith("零"))
{
tempoutstring=tempoutstring.substring(0,tempoutstring.length-1);
}
while(tempoutstring.endswith("元"))
{
tempoutstring=tempoutstring+"整";
}
this.outstring=tempoutstring;
}
#endregion
}
}