***************************
让ロロロ来帮你!!!
***************************
//下面是上面方法的实现代码,数字输入有以下限制
//不能输入除数字和逗号以外的符号(小数点?当然没有对应了。)
//数值不能太大,因为超过9000亿后我不知道该怎么读了(兆?)
//不能以0打头
public bool ChangeNumber(string sIn, ref string sOut)
{
bool result = false;
string[] out0 = {"零", "壹", "贰","叁", "肆", "伍", "陆", "柒", "捌","玖"};
string[] out1 = { "","拾", "佰", "千", "", "拾", "佰", "千","","拾", "佰", "千" };
string[] out2= {"万", "亿"};
sOut = "";
string sRet = "";
bool numberStarted = false;
bool oldNumberIsZero = false;
//允许输入","
sIn = sIn.Replace(",", "");
int count = sIn.Length;
if (count > 12)
{
//太大的数字(超过9000亿)
return result;
}
if ("0".Equals(sIn.Substring(0, 1)))
{
//0打头的数字
return result;
}
for (int i = 0;
i < sIn.Length;
i++)
{
//取得字符
string sBit = sIn.Substring(sIn.Length - i-1, 1);
//检查有效性
if ("0".CompareTo(sBit) > 0 || "9".CompareTo(sBit) < 0)
{
return result;
}
if ("0".Equals(sBit))
{
if (!numberStarted)
{
continue;
}
else
if (!oldNumberIsZero &&
i!=4 &&
i!=8)
{
sRet = out0[0] + sRet;
}
oldNumberIsZero = true;
if (i == 4)
{
sRet = out2[0] + sRet;
}
else
if (i == 8)
{
sRet = out2[1] + sRet;
}
}
else
{
numberStarted = true;
sRet = out0[int.Parse(sBit) ] + out1 + sRet;
if(i==4)
{
sRet = sRet.Substring(0, 1) + out2[0] + sRet.Substring(1, sRet.Length -1);
}
else
if (i==8)
{
sRet = sRet.Substring(0, 1) + out2[1] + sRet.Substring(1, sRet.Length -1);
}
oldNumberIsZero = false;
}
}
sOut = sRet;
return true;
}
//以下时调用方法
string sout = "";
bool changeok = ChangeNumber("10234567", ref sout);
if(changeok)
{
//
return value was setted in sout
}
***************************
有问题么?让ロロロ来帮你吧
***************************