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


     数字转换类 
    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(02== "一十")
            { str 
    = str.Substring(1); }
            
    if (str.Length > 1 && str.Substring(02== "壹拾")
            { 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 = 0break;
                
    case DayOfWeek.Monday: week = 1break;
                
    case DayOfWeek.Tuesday: week = 2break;
                
    case DayOfWeek.Wednesday: week = 3break;
                
    case DayOfWeek.Thursday: week = 4break;
                
    case DayOfWeek.Friday: week = 5break;
                
    case DayOfWeek.Saturday: week = 6break;
            }
            
    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%10false);
            }
            
    else
            { str 
    = Chinese(m, false); }
            
    if (str == "廿")
            { str 
    += ""; }
            
    return str;
        }
    }

  • 相关阅读:
    python笔记-datetime-logging
    python笔记-json-base64-hashlib
    python笔记-redis数据库
    python笔记-mysql命令使用示例(使用pymysql执行)
    python笔记-python程序中操作mysql数据库
    python笔记-mysql约束条件与表关系
    python笔记-mysql查询
    python笔记-mysql基本命令
    Vue移动端项目模板h5
    基于环信SDK的IM即时通讯填坑之路(vue)
  • 原文地址:https://www.cnblogs.com/yigedaizi/p/1661590.html
Copyright © 2020-2023  润新知