冷风.NET

    ---默默無聞
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

今天從新整理的大小寫數據轉換

Posted on 2005-07-05 11:40  冷风.net  阅读(971)  评论(0编辑  收藏  举报

目前試用了個還沒有發現什麼問題,感覺還行吧,所以發來供大家參考

1. 引用命名空間:using System.Text.RegularExpressions;(操作正則表達式)
2. 小寫轉大寫

public static string sToh(string ch)
            
{
                
string str = "";
                
switch(ch)
                
{
                    
case "1":
                        str 
= "";
                        
break;
                    
case "2":
                        str 
= "";
                        
break;
                    
case "3":
                        str 
= "";
                        
break;
                    
case "4":
                        str 
= "";
                        
break;
                    
case "5":
                        str 
= "";
                        
break;
                    
case "6":
                        str 
= "";
                        
break;
                    
case "7":
                        str 
= "";
                        
break;
                    
case "8":
                        str 
= "";
                        
break;
                    
case "9":
                        str 
= "";
                        
break;
                    
default:
                        str 
= "";
                        
break;
                }

                
return str;
            }

3. 獲得數位位數
private static string getBit(int ilen)
        
{
            
string str = "";
            
switch(ilen)
            
{
                
case 2:
                    str 
= "";
                    
break;
                
case 3:
                    str 
= "";
                    
break;
                
case 4:
                    str 
= "";
                    
break;
                
case 5:
                    str 
= "";
                    
break;
                
case 6:
                    str 
= "";
                    
break;
                
case 7:
                    str 
= "";
                    
break;
                
case 8:
                    str 
= "";
                    
break;
                
case 9:
                    str 
= "";
                    
break;
                
case 10:
                    str 
= "";
                    
break;
                
case 11:
                    str 
= "";
                    
break;
                
case 12:
                    str 
= "";
                    
break;
                
case 13:
                    str 
= "";
                    
break;
                
case 14:
                    str 
= "";
                    
break;
                
case 15:
                    str 
= "";
                    
break;
                
case 16:
                    str 
= "";
                    
break;
                
default:
                    str 
= "";
                    
break;
            }
目前只寫到了仟兆,如需更多只需往後添加即可
4.  轉換
 1public static string ConventGig(string money)
 2        {
 3            string strTemp = money;
 4            string Decimal = "";    //小數
 5            string strValue = "";
 6            string strDecimal = "";
 7            if( money.IndexOf(".")>0)
 8            {
 9                strDecimal = "";
10                strTemp=money.Substring(0,money.IndexOf("."));
11                Decimal = money.Substring(money.IndexOf(".")+1);
12            }

13            try
14            {
15                strTemp = Convert.ToInt64(strTemp).ToString();
16            }

17            catch
18            {
19                return "輸入不正確的數據!";
20            }

21            int iLen = strTemp.Length;
22            if(strTemp.Length>16return "數據過大無法轉換";
23            for(int i=0; i<strTemp.Length; i++)
24            {
25                strValue += sToh(strTemp.Substring(i,1)) + getBit(iLen);
26                iLen--;
27            }

28            //小數
29            for(int i=0; i<Decimal.Length; i++)
30            {
31                strDecimal += sToh(Decimal.Substring(i,1));
32            }

33            Regex regex = new Regex("零+[拾,佰,仟,萬,億,兆]");
34            strValue = regex.Replace(strValue,"");
35            regex = new Regex("零{2,16}");
36            strValue = regex.Replace(strValue,"");
37            regex = new Regex("(萬|億|兆){1}零");
38            strValue = regex.Replace(strValue,"$1");
39            regex = new Regex("點$");
40            strDecimal = regex.Replace(strDecimal,"");
41            regex = new Regex("零+$");
42            strDecimal = regex.Replace(strDecimal,"");
43            return strValue + strDecimal;
44        }

5. 試用
0.1000500  輸出的結果為 >>  零點壹零零零伍
1008000500452008.12345  輸出的結果為 >> 壹仟零捌兆伍億肆拾伍萬貳仟零捌點壹貳參肆伍