X龙@China .Net 'blog

需要的不仅仅是工作,而是通过努力得来的美好将来。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

将数字转换中文

Posted on 2010-03-15 17:30  X龙  阅读(260)  评论(0编辑  收藏  举报
代码
  /// <summary>
        
/// 将字符串中的数字字符串转换成简体中文
        
/// </summary>
        
/// <param name="digital"></param>
        
/// <returns></returns>
        public static string ConvertDigitalToChinese(string digital)
        {
            
char[] chrChinese = { '''''''''''''''''''' };            
            
char[] digitalArr = digital.ToCharArray();
            
string result = string.Empty;

            
foreach (char c in digitalArr)
            {
                
switch (c)
                {
                    
case '0':
                        result 
+= chrChinese[0].ToString();
                        
break;
                    
case '1':
                        result 
+= chrChinese[1].ToString();
                        
break;

                    
case '2':
                        result 
+= chrChinese[2].ToString();
                        
break;

                    
case '3':
                        result 
+= chrChinese[3].ToString();
                        
break;

                    
case '4':
                        result 
+= chrChinese[4].ToString();
                        
break;

                    
case '5':
                        result 
+= chrChinese[5].ToString();
                        
break;

                    
case '6':
                        result 
+= chrChinese[6].ToString();
                        
break;

                    
case '7':
                        result 
+= chrChinese[7].ToString();
                        
break;

                    
case '8':
                        result 
+= chrChinese[8].ToString();
                        
break;

                    
case '9':
                        result 
+= chrChinese[9].ToString();
                        
break;
                    
default:
                        result 
+= c.ToString();
                        
break;
                }
            }
            
return result;
        }
       
        
/// <summary>
        
/// 将数字转换成简体中文
        
/// </summary>
        
/// <param name="digital"></param>
        
/// <returns></returns>
        public static string ConvertDigitalToChinese(int digital)
        {
            
char[] chrChinese = { '''''''''''''''''''' };
            
char[] digitalArr = digital.ToString().ToCharArray();
            
string result = string.Empty;

            
foreach (char c in digitalArr)
            {
                result 
+= chrChinese[c - '0'];
                result 
+= chrChinese[System.Convert.ToInt32(c.ToString())];
            }
            
return result;
        }

 

点击这里给我发消息http://wp.qq.com/index.html