源代码:
<%@ Page language="c#" %>
<%@ import NameSpace="System.Security.Cryptography" %><html>
<head>
<title>TripleDES(3DES)加密器</title>
<script language="C#" runat="server">
private void Page_Load(Object sender,EventArgs e)
{
Response.Write(ReadRMB("7654321.5"));
}//将阿拉伯数字表示的人民币金额转换成大写的汉字金额。注;阿拉佰数字的整数和小数位分别不得超过16位
public string ReadRMB(string numRMB)
{
//string numRMB=strNum;
string[] arrCNNumber={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
string[] arrUnit={"仟万亿","佰万亿","拾万亿","万亿","仟亿","佰亿","拾亿","亿","仟万","佰万","拾万","万","仟","佰","拾",""};
int index=numRMB.IndexOf('.');
string numPart1=numRMB.Substring(0,index); //取整数部分
string numPart2=numRMB.Substring(index+1,numRMB.Length-index-1); //取小数部分
string CNRMB1="",CNRMB2=""; //大写汉字金额整数和小数部分
string unit=" ";
for(int i=0;i<numPart1.Length;i++)
{
unit=arrUnit[arrUnit.Length-numPart1.Length+i]; //单位
if(numPart1.Substring(i,1)=="0") //若当前位为0
{
if(CNRMB1.Substring(CNRMB1.Length-1,1)=="零") //若前一位也为0,则不读当前位
{
if(unit.Substring(0,unit.Length-1)=="") //若当前位是是单位位,则需加上单位
{
CNRMB1+=(""+unit);
}
else
{
CNRMB1+="";
}
}
else //前一位不为0
{
if(unit.Substring(0,unit.Length-1)=="") //若当前位是是单位位,则直接转为单位,否则转为“零”
{
CNRMB1+=unit;
}
else
{
CNRMB1+="零";
}
}
}
else
{
int n=Convert.ToInt32(numPart1.Substring(i,1));
//若当前位不是处在仟、万、亿等单位位的位置上(如拾万、佰万、仟亿等),则须省掉末尾的单位(仟、万、亿)
if(unit.Length==1)
{
CNRMB1+=(arrCNNumber[n]+unit);
}
else
{
unit=unit.Substring(0,unit.Length-1);
CNRMB1+=(arrCNNumber[n]+unit);
}
}
}
//小数部分的转换还未实现
return CNRMB1;
}
</script>
</head>
<body></body>
</html>错误症状;
Server Error in '/' Application.
--------------------------------------------------------------------------------Length cannot be less than zero.
Parameter name: length
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: lengthSource Error:
Line 61: else
Line 62: {
Line 63: unit=unit.Substring(0,unit.Length-1);
Line 64: CNRMB1+=(arrCNNumber[n]+unit);
Line 65: }
Source File: c:\Inetpub\wwwroot\RMB.aspx Line: 63 Stack Trace:
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +2848721
System.String.Substring(Int32 startIndex, Int32 length) +11
ASP.rmb_aspx.ReadRMB(String numRMB) in c:\Inetpub\wwwroot\RMB.aspx:63
ASP.rmb_aspx.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\RMB.aspx:10
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
<%@ Page language="c#" %>
<%@ import NameSpace="System.Security.Cryptography" %><html>
<head>
<title>TripleDES(3DES)加密器</title>
<script language="C#" runat="server">
private void Page_Load(Object sender,EventArgs e)
{
Response.Write(ReadRMB("7654321.5"));
}//将阿拉伯数字表示的人民币金额转换成大写的汉字金额。注;阿拉佰数字的整数和小数位分别不得超过16位
public string ReadRMB(string numRMB)
{
//string numRMB=strNum;
string[] arrCNNumber={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
string[] arrUnit={"仟万亿","佰万亿","拾万亿","万亿","仟亿","佰亿","拾亿","亿","仟万","佰万","拾万","万","仟","佰","拾",""};
int index=numRMB.IndexOf('.');
string numPart1=numRMB.Substring(0,index); //取整数部分
string numPart2=numRMB.Substring(index+1,numRMB.Length-index-1); //取小数部分
string CNRMB1="",CNRMB2=""; //大写汉字金额整数和小数部分
string unit=" ";
for(int i=0;i<numPart1.Length;i++)
{
unit=arrUnit[arrUnit.Length-numPart1.Length+i]; //单位
if(numPart1.Substring(i,1)=="0") //若当前位为0
{
if(CNRMB1.Substring(CNRMB1.Length-1,1)=="零") //若前一位也为0,则不读当前位
{
if(unit.Substring(0,unit.Length-1)=="") //若当前位是是单位位,则需加上单位
{
CNRMB1+=(""+unit);
}
else
{
CNRMB1+="";
}
}
else //前一位不为0
{
if(unit.Substring(0,unit.Length-1)=="") //若当前位是是单位位,则直接转为单位,否则转为“零”
{
CNRMB1+=unit;
}
else
{
CNRMB1+="零";
}
}
}
else
{
int n=Convert.ToInt32(numPart1.Substring(i,1));
//若当前位不是处在仟、万、亿等单位位的位置上(如拾万、佰万、仟亿等),则须省掉末尾的单位(仟、万、亿)
if(unit.Length==1)
{
CNRMB1+=(arrCNNumber[n]+unit);
}
else
{
unit=unit.Substring(0,unit.Length-1);
CNRMB1+=(arrCNNumber[n]+unit);
}
}
}
//小数部分的转换还未实现
return CNRMB1;
}
</script>
</head>
<body></body>
</html>错误症状;
Server Error in '/' Application.
--------------------------------------------------------------------------------Length cannot be less than zero.
Parameter name: length
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: lengthSource Error:
Line 61: else
Line 62: {
Line 63: unit=unit.Substring(0,unit.Length-1);
Line 64: CNRMB1+=(arrCNNumber[n]+unit);
Line 65: }
Source File: c:\Inetpub\wwwroot\RMB.aspx Line: 63 Stack Trace:
[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +2848721
System.String.Substring(Int32 startIndex, Int32 length) +11
ASP.rmb_aspx.ReadRMB(String numRMB) in c:\Inetpub\wwwroot\RMB.aspx:63
ASP.rmb_aspx.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\RMB.aspx:10
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
解决方案 »
- 问个关于限制查询的SQL语句
- 有关查询的问题!大哥的进
- 有没有操作XML的公共类
- Web.config配置问题
- 為什麽我在Dll的源代碼中加入了函數和類的注解,但是在引用這個DLL的程序中看不到? 哪位有例子?
- 在datagrid中数据更新的问题(高分求救)
- app_code里面取网站的session为何为空?
- login控件自定义加入验证码后,验证码不管对不对,只要user和password对,都验证成功。。。
- 求助:ApplicationException:拒绝访问.......
- asTreeview第三方树插件问题,急!!!!!
- PostBackUrl使用的问题
- ASP.NET 2.0 AJAX 怎么在原有项目中使用
呆呆虫
unit.Length-1 < 0, 自己调试一下吧。------------------------------
我也知道这unit.Length-1 < 0啊,但就是不知道怎么会这样?