【类】数字转汉字及其他转换

 

  数字转换类 
using  System;
using  System.Collections.Generic;
using  System.Text;

class  FString
{
     阿拉伯数字转汉字 
    
public   static   string  Chinese( long  n,  bool  fang)
    {
        
string  strn  =  n.ToString();
        
string  str  =   "" ;
        
string  nn  =   " 零壹贰叁肆伍陆柒捌玖 " ;
        
string  ln  =   " 零一二三四五六七八九 " ;

        
string  mm  =   "   拾佰仟萬拾佰仟亿拾佰仟萬兆拾佰仟萬亿 " ;
        
string  lm  =   "   十百千万十百千亿十百千万兆十百千万亿 " ;

        
int  i  =   0 ;
        
while  (i  <  strn.Length) // >>>>>>>>>>>>>>>>出现空格
        {

            
int  m  =   int .Parse(strn.Substring(i,  1 ));
            
if  (fang) // 返回繁体字
            {
                str 
+=  nn.Substring(m,  1 );
                
if  (lm.Substring(strn.Length  -  i,  1 !=   "   "  )
                { str 
+=  mm.Substring(strn.Length  -  i,  1 ); }
            }
            
else // 返回简体字
            {
                str 
+=  ln.Substring(m,  1 );
                
if  (lm.Substring(strn.Length  -  i,  1 !=   "   " )
                {
                    str 
+=  lm.Substring(strn.Length  -  i,  1 );
                }
            }
            i
++ ;
        }
        
if  (str.Substring(str.Length  -   1 ==   " " )
        { str 
=  str.Substring( 0 , str.Length  -   1 ); }
        
if  (str.Length > 1   &&  str.Substring( 0 2 ==   " 一十 " )
        { str 
=  str.Substring( 1 ); }
        
if  (str.Length  >   1   &&  str.Substring( 0 2 ==   " 壹拾 " )
        { str 
=  str.Substring( 1 ); }

        
return  str;
    }
     星期英文转中文 
    
public   static   string  WeekString(DayOfWeek d) // 转为中文星期
    {
        
string  week  =   "" ;
        
switch  (d)
        {
            
case  DayOfWeek.Sunday: week  =   " 星期日 " break ;
            
case  DayOfWeek.Monday: week  =   " 星期一 " break ;
            
case  DayOfWeek.Tuesday: week  =   " 星期二 " break ;
            
case  DayOfWeek.Wednesday: week  =   " 星期三 " break ;
            
case  DayOfWeek.Thursday: week  =   " 星期四 " break ;
            
case  DayOfWeek.Friday: week  =   " 星期五 " break ;
            
case  DayOfWeek.Saturday: week  =   " 星期六 " break ;
        }
        
return  week;
    }
    
    
public   static   int  WeekInt(DayOfWeek d)
    {
        
int  week  =   0 ;
        
switch  (d)
        {
            
case  DayOfWeek.Sunday: week  =   0 break ;
            
case  DayOfWeek.Monday: week  =   1 break ;
            
case  DayOfWeek.Tuesday: week  =   2 break ;
            
case  DayOfWeek.Wednesday: week  =   3 break ;
            
case  DayOfWeek.Thursday: week  =   4 break ;
            
case  DayOfWeek.Friday: week  =   5 break ;
            
case  DayOfWeek.Saturday: week  =   6 break ;
        }
        
return  week;
    }

    
public   static   string  WeekString( int  d) // 转为中文星期
    {
        
string  week  =   "" ;
        
switch  (d)
        {
            
case   0 : week  =   " 星期日 " break ;
            
case   1 : week  =   " 星期一 " break ;
            
case   2 : week  =   " 星期二 " break ;
            
case   3 : week  =   " 星期三 " break ;
            
case   4 : week  =   " 星期四 " break ;
            
case   5 : week  =   " 星期五 " break ;
            
case   6 : week  =   " 星期六 " break ;
        }
        
return  week;
    }

    
public   static   string  MonthString( int  m,  bool  fang) // 转为中文月份
    {
        
string  month  =  Chinese(m, fang)  +   " " ;
        
return  month;
    }

    
public   static   string  dayString( int  m) // 初几
    {
        
string  str  =   "" ;
        
if  (m  <   11 )
        {
            str 
=   " "   +  Chinese(m,  false );
        }
        
else   if  (m  <   30   &&  m  >   19 )
        {
            str 
=   " 廿 "   +  Chinese(m % 10 false );
        }
        
else
        { str 
=  Chinese(m,  false ); }
        
if  (str  ==   " 廿 " )
        { str 
+=   " " ; }
        
return  str;
    }
}

 

 

你可能感兴趣的:(转换)