本帖最后由 lxcnn 于 2008-11-20 21:01:24 编辑

解决方案 »

  1.   

    请参考
    public static string CmycurD(decimal num)
            {
                string str1 = "零壹贰叁肆伍陆柒捌玖";            //0-9所对应的汉字 
                string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //数字位所对应的汉字 
                string str3 = "";    //从原num值中取出的值 
                string str4 = "";    //数字的字符串形式 
                string str5 = "";  //人民币大写金额形式 
                int i;    //循环变量 
                int j;    //num的值乘以100的字符串长度 
                string ch1 = "";    //数字的汉语读法 
                string ch2 = "";    //数字位的汉字读法 
                int nzero = 0;  //用来计算连续的零值是几个 
                int temp;            //从原num值中取出的值             num = Math.Round(Math.Abs(num), 2);    //将num取绝对值并四舍五入取2位小数 
                str4 = ((long)(num * 100)).ToString();        //将num乘100并转换成字符串形式 
                j = str4.Length;      //找出最高位 
                if (j > 15) { return "溢出"; }
                str2 = str2.Substring(15 - j);   //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分             //循环取出每一位需要转换的值 
                for (i = 0; i < j; i++)
                {
                    str3 = str4.Substring(i, 1);          //取出需转换的某一位的值 
                    temp = Convert.ToInt32(str3);      //转换为数字 
                    if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15))
                    {
                        //当所取位数不为元、万、亿、万亿上的数字时 
                        if (str3 == "0")
                        {
                            ch1 = "";
                            ch2 = "";
                            nzero = nzero + 1;
                        }
                        else
                        {
                            if (str3 != "0" && nzero != 0)
                            {
                                ch1 = "零" + str1.Substring(temp * 1, 1);
                                ch2 = str2.Substring(i, 1);
                                nzero = 0;
                            }
                            else
                            {
                                ch1 = str1.Substring(temp * 1, 1);
                                ch2 = str2.Substring(i, 1);
                                nzero = 0;
                            }
                        }
                    }
                    else
                    {
                        //该位是万亿,亿,万,元位等关键位 
                        if (str3 != "0" && nzero != 0)
                        {
                            ch1 = "零" + str1.Substring(temp * 1, 1);
                            ch2 = str2.Substring(i, 1);
                            nzero = 0;
                        }
                        else
                        {
                            if (str3 != "0" && nzero == 0)
                            {
                                ch1 = str1.Substring(temp * 1, 1);
                                ch2 = str2.Substring(i, 1);
                                nzero = 0;
                            }
                            else
                            {
                                if (str3 == "0" && nzero >= 3)
                                {
                                    ch1 = "";
                                    ch2 = "";
                                    nzero = nzero + 1;
                                }
                                else
                                {
                                    if (j >= 11)
                                    {
                                        ch1 = "";
                                        nzero = nzero + 1;
                                    }
                                    else
                                    {
                                        ch1 = "";
                                        ch2 = str2.Substring(i, 1);
                                        nzero = nzero + 1;
                                    }
                                }
                            }
                        }
                    }
                    if (i == (j - 11) || i == (j - 3))
                    {
                        //如果该位是亿位或元位,则必须写上 
                        ch2 = str2.Substring(i, 1);
                    }
                    str5 = str5 + ch1 + ch2;                if (i == j - 1 && str3 == "0")
                    {
                        //最后一位(分)为0时,加上“整” 
                        str5 = str5 + '整';
                    }
                }
                if (num == 0)
                {
                    str5 = "零元整";
                }
                return str5;
            }
      

  2.   

            static void Main(string[] args)
            {
                string stNum = "九十八万一百一十一";
                char[] array = stNum.ToCharArray();
                int sum = 0;
                int num = 0;
                foreach (char c in array)
                {                
                    int nuit = GetUnit(c);
                    if (nuit == 0)//数字 
                    {
                        num = GetNum(c);
                    }
                    else
                    {
                        sum += num * nuit;
                        num = 0;
                    }                
                }
                sum += num;
            }        public static int GetNum(char num)
            {
                int Result = 0;
                switch (num)
                {
                    case '一': Result = 1; break;
                    case '二': Result = 2; break;
                    case '三': Result = 3; break;
                    case '四': Result = 4; break;
                    case '五': Result = 5; break;
                    case '六': Result = 6; break;
                    case '七': Result = 7; break;
                    case '八': Result = 8; break;
                    case '九': Result = 9; break;
                    default:
                        break;
                }
                return Result;
            }        public static int GetUnit(char num)
            {
                int Result = 0;
                switch (num)
                {
                    case '十': Result = 10; break;
                    case '百': Result = 100; break;
                    case '千': Result = 1000; break;
                    case '万': Result = 10000; break;
                    case '亿': Result = 10000; break;
                    default:
                        break;
                }
                return Result;
            }目前支持一万以内的.下班了,明天加一万以后的.
      

  3.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication8
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            int Result = 0;
                String Source = "三万零五十二"; //3$5!2            Source=Source.Replace("一", "1");
                Source = Source.Replace("二", "2");
                Source = Source.Replace("三", "3");
                Source = Source.Replace("四", "4");
                Source = Source.Replace("五", "5");
                Source = Source.Replace("六", "6");
                Source = Source.Replace("七", "7");
                Source = Source.Replace("八", "8");
                Source = Source.Replace("九", "9");
                Source = Source.Replace("十", "!");
                Source = Source.Replace("百", "@");
                Source = Source.Replace("千", "#");
                Source = Source.Replace("万", "$");
                Source = Source.Replace("亿", "%");
                Source = Source.Replace("零", "");            int Order=1;
                for (int i = Source.Length-1; i >= 0; i--)
                {
                    if (Char.IsDigit(Source[i]))
                        Result += Order * (Source[i] - 48);
                    else if (Source[i] == '!')
                        Order = 10;
                    else if (Source[i] == '@')
                        Order = 100;
                    else if (Source[i] == '#')
                        Order = 1000;
                    else if (Source[i] == '$')
                        Order = 10000;
                    else if (Source[i] == '%')
                        Order = 100000000;
                }
                MessageBox.Show(Result.ToString());  // 30052
            }
        }
    }
      

  4.   

    上面写的有个问题,更正了下using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication8
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            int Result = 0;
                String Source = "三十七万零二百三十三";            Source=Source.Replace("一", "1");
                Source = Source.Replace("二", "2");
                Source = Source.Replace("三", "3");
                Source = Source.Replace("四", "4");
                Source = Source.Replace("五", "5");
                Source = Source.Replace("六", "6");
                Source = Source.Replace("七", "7");
                Source = Source.Replace("八", "8");
                Source = Source.Replace("九", "9");
                Source = Source.Replace("十", "!");
                Source = Source.Replace("百", "@");
                Source = Source.Replace("千", "#");
                Source = Source.Replace("万", "$");
                Source = Source.Replace("亿", "%");
                Source = Source.Replace("零", "");            int Order=1;
                for (int i = Source.Length-1; i >= 0; i--)
                {
                    if (Char.IsDigit(Source[i]))
                        Result += Order * (Source[i] - 48);
                    else if (Source[i] == '!')
                        if (Order < 10)
                            Order = 10;
                        else
                            Order *= 10;
                    else if (Source[i] == '@')
                        if (Order < 100)
                            Order = 100;
                        else
                            Order *= 100;
                    else if (Source[i] == '#')
                        if (Order < 1000)
                            Order = 1000;
                        else
                            Order *= 1000;
                    else if (Source[i] == '$')
                        if (Order < 10000)
                            Order = 10000;
                        else
                            Order *= 10000;
                    else if (Source[i] == '%')
                        if (Order < 100000000)
                            Order = 100000000;
                        else
                            Order *= 100000000;
                }
                MessageBox.Show(Result.ToString());  // 370233
            }
        }
    }
      

  5.   

    最终版本,可以处理“十八”了,我也下班了using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication8
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            int Result = 0;
                String Source = "十八";            Source=Source.Replace("一", "1");
                Source = Source.Replace("二", "2");
                Source = Source.Replace("三", "3");
                Source = Source.Replace("四", "4");
                Source = Source.Replace("五", "5");
                Source = Source.Replace("六", "6");
                Source = Source.Replace("七", "7");
                Source = Source.Replace("八", "8");
                Source = Source.Replace("九", "9");
                Source = Source.Replace("十", "!");
                Source = Source.Replace("百", "@");
                Source = Source.Replace("千", "#");
                Source = Source.Replace("万", "$");
                Source = Source.Replace("亿", "%");
                Source = Source.Replace("零", "");            int Order=1;
                for (int i = Source.Length-1; i >= 0; i--)
                {
                    if (Char.IsDigit(Source[i]))
                        Result += Order * (Source[i] - 48);
                    else
                    {
                        if (Source[i] == '!')
                            if (Order < 10)
                                Order = 10;
                            else
                                Order *= 10;
                        else if (Source[i] == '@')
                            if (Order < 100)
                                Order = 100;
                            else
                                Order *= 100;
                        else if (Source[i] == '#')
                            if (Order < 1000)
                                Order = 1000;
                            else
                                Order *= 1000;
                        else if (Source[i] == '$')
                            if (Order < 10000)
                                Order = 10000;
                            else
                                Order *= 10000;
                        else if (Source[i] == '%')
                            if (Order < 100000000)
                                Order = 100000000;
                            else
                                Order *= 100000000;
                        if (i == 0)
                            Result += Order;
                    }
                    
                }
                MessageBox.Show(Result.ToString());  // 18
            }
        }
    }
      

  6.   


        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {
            string s = this.TextBox2.Text.Trim();
            int sum = 0;
            int index1 = 0;
            int n = 0;
            for (int i = 0; i < s.Length; i++)
            {
                n = ChangeNum(s[i]);
                if (n>9)
                {
                    if (sum==0 & index1==0)
                    {
                        index1 = n;
                    }
                    else
                    {
                        index1 *= n;
                    } 
                    sum += index1;
                }
                else
                {
                    index1 = n;
                }
               
            }
            if(n<10)
            {
                sum += index1;
            }
            this.Label1.Text = sum.ToString();
        }
        private int ChangeNum(char ch)
        {
            switch (ch)
            {
                case '一': return 1;
                case '二': return 2;
                case '三': return 3;
                case '四': return 4;
                case '五': return 5;
                case '六': return 6;
                case '七': return 7;
                case '八': return 8;
                case '九': return 9;            case '十': return 10;
                case '百': return 100;
                case '千': return 1000;
                case '万': return 10000;
                default: return 0;
            }
        }
      

  7.   

    Public Sub New() 
        InitializeComponent() 
        
        Dim Result As Integer = 0 
        Dim Source As String = "三十七万零二百三十三" 
        
        Source = Source.Replace("一", "1") 
        Source = Source.Replace("二", "2") 
        Source = Source.Replace("三", "3") 
        Source = Source.Replace("四", "4") 
        Source = Source.Replace("五", "5") 
        Source = Source.Replace("六", "6") 
        Source = Source.Replace("七", "7") 
        Source = Source.Replace("八", "8") 
        Source = Source.Replace("九", "9") 
        Source = Source.Replace("十", "!") 
        Source = Source.Replace("百", "@") 
        Source = Source.Replace("千", "#") 
        Source = Source.Replace("万", "$") 
        Source = Source.Replace("亿", "%") 
        Source = Source.Replace("零", "") 
        
        Dim Order As Integer = 1 
        For i As Integer = Source.Length - 1 To 0 Step -1 
            If [Char].IsDigit(Source(i)) Then 
                Result += Order * (Source(i) - 48) 
            ElseIf Source(i) = "!"c Then 
                If Order < 10 Then 
                    Order = 10 
                Else 
                    Order *= 10 
                End If 
            ElseIf Source(i) = "@"c Then 
                If Order < 100 Then 
                    Order = 100 
                Else 
                    Order *= 100 
                End If 
            ElseIf Source(i) = "#"c Then 
                If Order < 1000 Then 
                    Order = 1000 
                Else 
                    Order *= 1000 
                End If 
            ElseIf Source(i) = "$"c Then 
                If Order < 10000 Then 
                    Order = 10000 
                Else 
                    Order *= 10000 
                End If 
            ElseIf Source(i) = "%"c Then 
                If Order < 100000000 Then 
                    Order = 100000000 
                Else 
                    Order *= 100000000 
                End If 
            End If 
        Next 
        MessageBox.Show(Result.ToString()) 
        ' 370233 
    End Sub 
    哎,在构造函数里面写这么多东西!,不过学习了,呵呵.路过把他翻译成VB.NET代码完善一下嘛
      

  8.   


        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {
            string s = this.TextBox2.Text.Trim();
            int sum = 0;
            int index1 = 0;
            int n = 0;
            for (int i = 0; i < s.Length; i++)
            {
                n = ChangeNum(s[i]);
                if (n>9)
                {
                    if (sum==0 & index1==0)
                    {
                        index1 = n;
                    }
                    else
                    {
                        index1 *= n;
                    } 
                    sum += index1;
                }
                else
                {
                    index1 = n;
                }
               
            }
            if(n<10)
            {
                sum += index1;
            }
            this.Label1.Text = sum.ToString();
        }
        private int ChangeNum(char ch)
        {
            switch (ch)
            {
                case '零': return 0;
                case '一': return 1;
                case '二': return 2;
                case '三': return 3;
                case '四': return 4;
                case '五': return 5;
                case '六': return 6;
                case '七': return 7;
                case '八': return 8;
                case '九': return 9;            case '十': return 10;
                case '百': return 100;
                case '千': return 1000;
                case '万': return 10000;
                default: return 0;
            }
        }
    可以处理以下形式:  一、二、三、……、十、五十、六十七、一百、一百二十、二百三十七、三千、三千六百、五千八百七十、六千九百四十二  
    可以处理五百零六、一万零六、五万零六十、二万零六百、三万零六千
      

  9.   


    Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As EventArgs) 
        Dim s As String = Me.TextBox2.Text.Trim() 
        Dim sum As Integer = 0 
        Dim index1 As Integer = 0 
        Dim n As Integer = 0 
        For i As Integer = 0 To s.Length - 1 
            n = ChangeNum(s(i)) 
            If n > 9 Then 
                If sum = 0 And index1 = 0 Then 
                    index1 = n 
                Else 
                    index1 *= n 
                End If 
                sum += index1 
            Else 
                index1 = n 
            End If 
            
        Next 
        If n < 10 Then 
            sum += index1 
        End If 
        Me.Label1.Text = sum.ToString() 
    End Sub Private Function ChangeNum(ByVal ch As Char) As Integer 
        Select Case ch 
            Case "一"c 
                Return 1 
            Case "二"c 
                Return 2 
            Case "三"c 
                Return 3 
            Case "四"c 
                Return 4 
            Case "五"c 
                Return 5 
            Case "六"c 
                Return 6 
            Case "七"c 
                Return 7 
            Case "八"c 
                Return 8 
            Case "九"c 
                Return 9 
            
            Case "十"c 
                Return 10 
            Case "百"c 
                Return 100 
            Case "千"c 
                Return 1000 
            Case "万"c 
                Return 10000 
            Case Else 
                Return 0 
        End Select 
    End Function 翻译11楼的
      

  10.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Globalization;namespace Ex19_10
    {
        public partial class Fomr1 : Form
        {
            public Fomr1()
            {
                InitializeComponent();
            }        private void frmMoney_Load(object sender, EventArgs e)
            {        }// 
        
             
     
            ///   <summary>   
            ///   获得decimal类型数字的中文大写形势   
            ///   </summary>   
            ///   <param   name="D_Mstr_theMoney">decimal类型数字存储小写金钱</param>   
            ///   <returns>返回string类型的数字的中文大写形势</returns>
            public string UpMoney(decimal D_Mstr_theMoney)
            {
                string G_str_Money= "零壹贰叁肆伍陆柒捌玖"; //0-9所对应的汉字     
                string G_str_MoneyString = "万仟佰拾亿仟佰拾万仟佰拾元角分";   //数字位所对应的汉字     
                string G_str_Timoney = "";   //从原D_Mstr_theMoney值中取出的值     
                string G_str_NumberString = "";  //数字的字符串形式     
                string G_str_UpMoney = ""; //人民币大写金额形式     
                int i;         //循环变量     
                int j;         //D_Mstr_theMoney的值乘以100的字符串长度     
                string G_ch_Chine = "";  //数字的汉语读法     
                string G_ch_Chineses = ""; //数字位的汉字读法     
                int G_int_ZeroCount = 0;//用来计算连续的零值是几个     
                int G_int_G_int_temp; //从原D_Mstr_theMoney值中取出的值     
                D_Mstr_theMoney = Math.Round(Math.Abs(D_Mstr_theMoney), 2);//将D_Mstr_theMoney取绝对值并四舍五入取2位小数     
                G_str_NumberString = ((long)(D_Mstr_theMoney * 100)).ToString(); //将D_Mstr_theMoney乘100并转换成字符串形式     
                j = G_str_NumberString.Length;//找出最高位     
                if (j > 15) { return "溢出"; }
                G_str_MoneyString = G_str_MoneyString.Substring(15 - j); //取出对应位数的G_str_MoneyString的值。如:200.55,j为5所以G_str_MoneyString=佰拾元角分                 //循环取出每一位需要转换的值     
                for (i = 0; i < j; i++)
                {
                    G_str_Timoney = G_str_NumberString.Substring(i, 1); //取出需转换的某一位的值     
                    G_int_G_int_temp = Convert.ToInt32(G_str_Timoney); //转换为数字     
                    if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15))
                    {
                        //当所取位数不为元、万、亿、万亿上的数字时     
                        if (G_str_Timoney == "0")
                        {
                            G_ch_Chine = "";
                            G_ch_Chineses = "";
                            G_int_ZeroCount = G_int_ZeroCount + 1;
                        }
                        else
                        {
                            if (G_str_Timoney != "0" && G_int_ZeroCount != 0)
                            {
                                G_ch_Chine = "零" + G_str_Money.Substring(G_int_G_int_temp * 1, 1);
                                G_ch_Chineses = G_str_MoneyString.Substring(i, 1);
                                G_int_ZeroCount = 0;
                            }
                            else
                            {
                                G_ch_Chine = G_str_Money.Substring(G_int_G_int_temp * 1, 1);
                                G_ch_Chineses = G_str_MoneyString.Substring(i, 1);
                                G_int_ZeroCount = 0;
                            }
                        }
                    }
                    else
                    {
                        //该位是万亿,亿,万,元位等关键位     
                        if (G_str_Timoney != "0" && G_int_ZeroCount != 0)
                        {
                            G_ch_Chine = "零" + G_str_Money.Substring(G_int_G_int_temp * 1, 1);
                            G_ch_Chineses = G_str_MoneyString.Substring(i, 1);
                            G_int_ZeroCount = 0;
                        }
                        else
                        {
                            if (G_str_Timoney != "0" && G_int_ZeroCount == 0)
                            {
                                G_ch_Chine = G_str_Money.Substring(G_int_G_int_temp * 1, 1);
                                G_ch_Chineses = G_str_MoneyString.Substring(i, 1);
                                G_int_ZeroCount = 0;
                            }
                            else
                            {
                                if (G_str_Timoney == "0" && G_int_ZeroCount >= 3)
                                {
                                    G_ch_Chine = "";
                                    G_ch_Chineses = "";
                                    G_int_ZeroCount = G_int_ZeroCount + 1;
                                }
                                else
                                {
                                    if (j >= 11)
                                    {
                                        G_ch_Chine = "";
                                        G_int_ZeroCount = G_int_ZeroCount + 1;
                                    }
                                    else
                                    {
                                        G_ch_Chine = "";
                                        G_ch_Chineses = G_str_MoneyString.Substring(i, 1);
                                        G_int_ZeroCount = G_int_ZeroCount + 1;
                                    }
                                }
                            }
                        }
                    }
                    if (i == (j - 11) || i == (j - 3))
                    {
                        //如果该位是亿位或元位,则必须写上     
                        G_ch_Chineses = G_str_MoneyString.Substring(i, 1);
                    }
                    G_str_UpMoney = G_str_UpMoney + G_ch_Chine + G_ch_Chineses;                if (i == j - 1 && G_str_Timoney == "0")
                    {
                        //最后一位(分)为0时,加上“整”     
                        G_str_UpMoney = G_str_UpMoney + '整';
                    }
                }
                if (D_Mstr_theMoney == 0)
                {
                    G_str_UpMoney = "零元整";
                }
                return G_str_UpMoney;
            }     
            private void button1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "")
                {
                    MessageBox.Show("请填写要转换的金额");
                    return;
                }
                else
                {
                    textBox2.Text = this.UpMoney(Convert.ToDecimal(textBox1.Text));
                }
            }
            //判断输入类型
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {            if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 46)
                {                e.Handled=true;
                      
                }
            }   
     
           
        }// end
    }
      

  11.   

    只提供思路
    把汉字的字符串中的数字筛选出来,然后用switch把各种0-9的数字转换为阿拉伯数字。。很简单的思路。。效率有限
      

  12.   


    int GetNumber(string str)
    {
        int num = 0, bit = 1, bit2 = 1;
        for (int i = str.Length - 1; i >= 0; i--)
        {
            int m = "零一二三四五六七八九十百千万亿".IndexOf(str[i]);
            if (m >= 0 && m <= 9) num = num + (m * bit);
            else if (m >= 10 && m <= 12) bit = bit2 * (int)Math.Pow(10, m - 9);
            else if (m >= 13) bit = bit2 = (int)Math.Pow(10000, m - 12);
        }
        return num;
    }
      

  13.   

    完整例子:
    static void Main()
    {
        string[] words = { "三千零一万零三百", "三百一十", "三千万零一十", "五千零一" };
        foreach (string word in words)
        {
            Console.WriteLine(word + ": " + GetNumber(word));
        }
        Console.ReadKey();
    }static int GetNumber(string str)
    {
        int num = 0, bit = 1, bit2 = 1;
        for (int i = str.Length - 1; i >= 0; i--)
        {
            int m = "零一二三四五六七八九十百千万亿".IndexOf(str[i]);
            if (m >= 0 && m <= 9) num = num + (m * bit);
            else if (m >= 10 && m <= 12) bit = bit2 * (int)Math.Pow(10, m - 9);
            else if (m >= 13) bit = bit2 = (int)Math.Pow(10000, m - 12);
        }
        return num;
    }
    输出结果:三千零一万零三百: 30010300
    三百一十: 310
    三千万零一十: 30000010
    五千零一: 5001

      

  14.   

    用递归调用,先帖个十万以内的(不包括十万)
    明天再写以后的。
    public long add(String str)
    {
    //存储strCHup里具体汉字的数字值
    long mid=0;
    //存储strNumup里具体汉字的数字值
    int number=0;
    //存储传入字符串的最高级别单位在strCHup数组里的索引.
    int num=-1;
    for(int i=0;i<strCHup.length;i++)
    {
    mid=0;
    number=0;
    num=-1;
    num=str.indexOf(strCHup[i]);
    char ch=' ';
    ////////////////////////////////////////////////////////////////
    if(num!=-1)
    {

    switch(i)
    {
    case 0:
    mid=100000000;
    break;
    case 1:
    mid=10000;
    break;
    case 2:
    mid=1000;
    break;
    case 3:
    mid=100;
    break;
    case 4:
    mid=10;
    break;
    }


    ch = (str.toCharArray())[num-1];



    //////////////////////////////////////////////////////
    }
    //////////////////////////////////////////////////////////////////
    if(str.length()==1){

    ch = (str.toCharArray())[0];
    }
    switch(ch)
    {
    case '零':
    number=0;
    break;
    case '一':
    number=1;
    break;
    case '二':
    number=2;
    break;
    case '三':
    number=3;
    break;
    case '四':
    number=4;
    break;
    case '五':
    number=5;
    break;
    case '六':
    number=6;
    break;
    case '七':
    number=7;
    break;
    case '八':
    number=8;
    break;
    case '九':
    number=9;
    break;
    }
    /////////////////////////////////////////////////////////////////



    if(num!=-1)
    {
    break;
    }


    }
    if(num==-1)
    {
    return number;
    }

    String strLeft = str.substring(num+1);
    return (number*mid)+add(strLeft);
    }
      

  15.   

    慢慢学习PS: 
    我的目标是 ----> ^_^
      

  16.   


            static void Main(string[] args)
            {
                string stNum = "三亿九十八万一百一十一";
                char[] array = stNum.ToCharArray();
                int sum = 0;
                int num = 0;
                foreach (char c in array)
                {                
                    int nuit = GetUnit(c);
                    if (nuit == 0)//数字 
                    {
                        num = GetNum(c);
                    }
                    else
                    {
                        if (nuit >= 10000 && sum > 10)
                        {
                            sum += num;
                            sum = sum * nuit;
                        }
                        else
                        {
                            sum += num * nuit;
                        }
                        num = 0;
                    }                
                }
                sum += num;
                Console.WriteLine(sum);
                Console.ReadLine();
            }        public static int GetNum(char num)
            {
                int Result = 0;
                switch (num)
                {
                    case '一': Result = 1; break;
                    case '二': Result = 2; break;
                    case '三': Result = 3; break;
                    case '四': Result = 4; break;
                    case '五': Result = 5; break;
                    case '六': Result = 6; break;
                    case '七': Result = 7; break;
                    case '八': Result = 8; break;
                    case '九': Result = 9; break;
                    default:
                        break;
                }
                return Result;
            }        public static int GetUnit(char num)
            {
                int Result = 0;
                switch (num)
                {
                    case '十': Result = 10; break;
                    case '百': Result = 100; break;
                    case '千': Result = 1000; break;
                    case '万': Result = 10000; break;
                    case '亿': Result = 10000; break;
                    default:
                        break;
                }
                return Result;
            }
      

  17.   


    bug报告一十: 10 
    十: 0 

      

  18.   


    static int GetNumber(string str)
    {
        if (str == "十") str = "一十";    int num = 0, bit = 1, bit2 = 1;
        for (int i = str.Length - 1; i >= 0; i--)
        {
            int m = "零一二三四五六七八九十百千万亿".IndexOf(str[i]);
            if (m >= 0 && m <= 9) num = num + (m * bit);//零一二三四五六七八九
            else if (m >= 10 && m <= 12) bit = bit2 * (int)Math.Pow(10, m - 9);
            else if (m >= 13) bit = bit2 = (int)Math.Pow(10000, m - 12);
        }
        return num;
    }25 楼 0009 的修改版本
      

  19.   


    谢谢qshzf ,不过改成这样好一点
    static void Main()
    {
        string[] words = { "三千零一万零三百", "三百一十", "三千万零一十", "五千零一", "十五" };
        foreach (string word in words)
        {
            Console.WriteLine(word + ": " + GetNumber(word));
        }
        Console.ReadKey();
    }static int GetNumber(string str)
    {
        if (str[0] == '十') str = '一' + str;
        int num = 0, bit = 1, bit2 = 1;
        for (int i = str.Length - 1; i >= 0; i--)
        {
            int m = "零一二三四五六七八九十百千万亿".IndexOf(str[i]);
            if (m >= 0 && m <= 9) num = num + (m * bit);
            else if (m >= 10 && m <= 12) bit = bit2 * (int)Math.Pow(10, m - 9);
            else if (m >= 13) bit = bit2 = (int)Math.Pow(10000, m - 12);
        }
        return num;
    }
      

  20.   

    这个应该没什么错误了        static void Main(string[] args)
            {
                int i;
                Console.WriteLine(NumberConvert("一百十八", out i));
                Console.WriteLine(NumberConvert("十万", out i));
                Console.WriteLine(NumberConvert("一百零一", out i));
                Console.WriteLine(NumberConvert("一百万零一", out i));
                Console.WriteLine(NumberConvert("十万零一百零一", out i));            Console.Read();
            }        public static int NumberConvert(string number, out int maxunit)
            {
                if (number.Length == 0) { maxunit = 0; return 0; }
                int result = 0;
                int unit = 1;
                int offset = 0;            
                switch (number[0])
                {
                    case '一': result = 1; offset++; break;
                    case '二': result = 2; offset++; break;
                    case '三': result = 3; offset++; break;
                    case '四': result = 4; offset++; break;
                    case '五': result = 5; offset++; break;
                    case '六': result = 6; offset++; break;
                    case '七': result = 7; offset++; break;
                    case '八': result = 8; offset++; break;
                    case '九': result = 9; offset++; break;
                    case '零': offset ++; break;
                    case '十': result = 1; break;
                }
                if (number.Length == offset) { maxunit = 0; return result; }
                switch (number[offset])
                {
                    case '十': unit = 10; offset++; break;
                    case '百': unit = 100; offset++; break;
                    case '千': unit = 1000; offset++; break;
                    case '万': unit = 10000; offset++; break;
                    case '亿': unit = 100000000; offset++; break;
                }
                int subResult = NumberConvert(number.Substring(offset), out maxunit);
                if (maxunit < unit) maxunit = unit;
                else if (maxunit == unit) maxunit = unit = unit * unit;
                else unit = unit * maxunit;
                return result * unit + subResult;
            }
      

  21.   

    当然,如果考虑有非法字符的话在递归之前加上一句:if (offset == 0) throw new Exception(“非法字符”);
      

  22.   

    发现一个问题
    “一万零十一”这个有问题,发觉要符合人们的习惯也很BT阿。
    修改之后:
            static void Main(string[] args)
            {
                int i;
                Console.WriteLine(NumberConvert("一百十八", out i));
                Console.WriteLine(NumberConvert("十万", out i));
                Console.WriteLine(NumberConvert("一百零一", out i));
                Console.WriteLine(NumberConvert("一百万零一", out i));
                Console.WriteLine(NumberConvert("十万零一百零一", out i));
                Console.WriteLine(NumberConvert("十万零十一", out i));
                Console.Read();
            }        public static int NumberConvert(string number, out int maxunit)
            {
                if (number.Length == 0) { maxunit = 0; return 0; }
                int result = 0;
                int offset = 0;
                switch (number[0])
                {
                    case '一': result = 1; offset++; break;
                    case '二': result = 2; offset++; break;
                    case '三': result = 3; offset++; break;
                    case '四': result = 4; offset++; break;
                    case '五': result = 5; offset++; break;
                    case '六': result = 6; offset++; break;
                    case '七': result = 7; offset++; break;
                    case '八': result = 8; offset++; break;
                    case '九': result = 9; offset++; break;
                    case '十': result = 1; break;
                }
                if (number.Length == offset) { maxunit = 1; return result; }
                int unit = 1;
                switch (number[offset])
                {
                    case '零': unit = 0; offset++; break;//零实际上不是个数值
                    case '十': unit = 10; offset++; break;
                    case '百': unit = 100; offset++; break;
                    case '千': unit = 1000; offset++; break;
                    case '万': unit = 10000; offset++; break;
                    case '亿': unit = 100000000; offset++; break;
                }
                if (offset == 0) throw new Exception();
                int subResult = NumberConvert(number.Substring(offset), out maxunit);
                if (maxunit < unit) maxunit = unit;
                else if (maxunit == unit) maxunit = unit = unit * unit;
                else unit = unit * maxunit;
                return result * unit + subResult;
            }
      

  23.   

    两个递归调用函数实现十万亿以内的数字
    但是输入一定要准确,没有处理异常情况.
    大家测试一下,看还有哪些地方有问题.
    public class work {

    String [] strCHup ={"亿",
    "万","千","百","十"};
    public long excuteCharge(String str,int start)
    {
    long midNumber=0;
    int bre=-1;
    int split = 0;
    for(int i=start;i<strCHup.length;i++)
    {
    bre =  str.indexOf(strCHup[i]);
    if(bre!=-1)
    {
    split=i;
    switch(i)
    {
    case 0:
    midNumber=100000000;
    break;
    case 1:
    midNumber=10000;
    break;
    case 2:
    midNumber=1000;
    break;
    case 3:
    midNumber=100;
    break;
    case 4:
    midNumber=10;
    break;
    }

    break;
    }

    } if(bre==-1)
    {
    return add(str);
    }
    else
    {

    if(str.length()==bre+1)
    {
    return add(str.substring(0, str.length()-1))*midNumber;
    }
    else
    {
    String[] strPart = str.split(strCHup[split]);
    return  (add(strPart[0])*midNumber)+excuteCharge(strPart[1],0);
    }
    }

    }

    public long add(String str)
    {
    //存储strCHup里具体汉字的数字值
    long mid=0;
    //存储strNumup里具体汉字的数字值
    int number=0;
    //存储传入字符串的最高级别单位在strCHup数组里的索引.
    int num=-1;
    for(int i=0;i<strCHup.length;i++)
    {
    mid=0;
    number=0;
    num=-1;
    num=str.indexOf(strCHup[i]);
    char ch=' ';
    ////////////////////////////////////////////////////////////////
    if(num!=-1)
    {

    switch(i)
    {
    case 0:
    mid=100000000;
    break;
    case 1:
    mid=10000;
    break;
    case 2:
    mid=1000;
    break;
    case 3:
    mid=100;
    break;
    case 4:
    mid=10;
    break;
    }


    ch = (str.toCharArray())[num-1];



    //////////////////////////////////////////////////////
    }
    //循环结束
    //////////////////////////////////////////////////////////////////
    if(str.length()==1){

    ch = (str.toCharArray())[0];
    }
    //防止几万零几这样的数.
    else if((str.length()==2)&&((str.toCharArray())[0]=='零'))
    {
    ch = (str.toCharArray())[1];
    }
    switch(ch)
    {
    case '零':
    number=0;
    break;
    case '一':
    number=1;
    break;
    case '二':
    number=2;
    break;
    case '三':
    number=3;
    break;
    case '四':
    number=4;
    break;
    case '五':
    number=5;
    break;
    case '六':
    number=6;
    break;
    case '七':
    number=7;
    break;
    case '八':
    number=8;
    break;
    case '九':
    number=9;
    break;
    }
    /////////////////////////////////////////////////////////////////



    if(num!=-1)
    {
    break;
    }


    }
    if(num==-1)
    {
    return number;
    }

    String strLeft = str.substring(num+1);
    return (number*mid)+add(strLeft);
    }}
      

  24.   

    谢谢大家给出这么多解决法,对上面给出的算法经过逐一测试(java代码不含在内,sorry,没java环境),
    测试样本: "三千零一万零三百零一", "三百一十", "三千万零一十一", "五千零一", "十五", "八万零十一","十","一十五","一十","一十九","二十","二十一","一百","一百零一","一百一十","一百一十一"
    但发现都存在一个问题:
    如: 八万零十一 80011, 上面的很多都解析成了80001, 只有"danjiewu"的解决办法能正确识别分就给我们的danjiewu兄了,其它的兄弟也会有辛苦分!