英文转中文和人民币小写转大写

来源:互联网 发布:狮子数学脱口秀 知乎 编辑:程序博客网 时间:2024/05/22 03:27

public static string PinYin(string mystr)
  { //指转换一个中文
   string tt;
   if ((mystr.ToUpper().CompareTo("A")>=0 &&
    mystr.ToUpper().CompareTo("Z")<=0)|| (mystr.ToUpper().CompareTo("0")>=0 &&
    mystr.ToUpper().CompareTo("9")<=0))
   {
    tt=mystr;
    return tt;
   }
   else if (Asc(mystr) < Asc("啊"))
   {
    tt="1";
    return tt;
   }
   else if (Asc(mystr) >= Asc("啊") && Asc(mystr) < Asc("芭"))
   {
    tt="a";
    return tt;
   }
   else if (Asc(mystr) >= Asc("芭") && Asc(mystr) < Asc("擦"))
   {
    tt="b";
    return tt;
   }
   else if (Asc(mystr) >= Asc("擦") && Asc(mystr) < Asc("搭"))
   {
    tt="c";
    return tt;
   }
   else if (Asc(mystr) >= Asc("搭") && Asc(mystr) < Asc("蛾"))
   {
    tt="d";
    return tt;
   }
   else if (Asc(mystr) >= Asc("蛾") && Asc(mystr) < Asc("发"))
   {
    tt="e";
    return tt;
   }
   else if (Asc(mystr) >= Asc("发") && Asc(mystr) < Asc("噶"))
   {
    tt="f";
    return tt;
   }
   else if (Asc(mystr) >= Asc("噶") && Asc(mystr) < Asc("哈"))
   {
    tt="g";
    return tt;
   }
   else if (Asc(mystr) >= Asc("哈") && Asc(mystr) < Asc("击"))
   {
    tt="h";
    return tt;
   }
   else if (Asc(mystr) >= Asc("击") && Asc(mystr) < Asc("喀"))
   {
    tt="j";
    return tt;
   }
   else if (Asc(mystr) >= Asc("喀") && Asc(mystr) < Asc("垃"))
   {
    tt="k";
    return tt;
   }
   else if (Asc(mystr) >= Asc("垃") && Asc(mystr) < Asc("妈"))
   {
    tt="l";
    return tt;
   }
   else if (Asc(mystr) >= Asc("妈") && Asc(mystr) < Asc("拿"))
   {
    tt="m";
    return tt;
   }
   else if (Asc(mystr) >= Asc("拿") && Asc(mystr) < Asc("哦"))
   {
    tt="n";
    return tt;
   }
   else if (Asc(mystr) >= Asc("哦") && Asc(mystr) < Asc("啪"))
   {
    tt="o";
    return tt;
   }
   else if (Asc(mystr) >= Asc("啪") && Asc(mystr) < Asc("期"))
   {
    tt="p";
    return tt;
   }
   else if (Asc(mystr) >= Asc("期") && Asc(mystr) < Asc("然"))
   {
    tt="q";
    return tt;
   }
   else if (Asc(mystr) >= Asc("然") && Asc(mystr) < Asc("撒"))
   {
    tt="r";
    return tt;
   }
   else if (Asc(mystr) >= Asc("撒") && Asc(mystr) < Asc("塌"))
   {
    tt="s";
    return tt;
   }
   else if (Asc(mystr) >= Asc("塌") && Asc(mystr) < Asc("挖"))
   {
    tt="t";
    return tt;
   }
   else if (Asc(mystr) >= Asc("挖") && Asc(mystr) < Asc("昔"))
   {
    tt="w";
    return tt;
   }
   else if (Asc(mystr) >= Asc("昔") && Asc(mystr) < Asc("压"))
   {
    tt="x";
    return tt;
   }
   else if (Asc(mystr) >= Asc("压") && Asc(mystr) < Asc("匝"))
   {
    tt="y";
    return tt;
   }
   else if (Asc(mystr) >= Asc("匝") )
   {
    tt="z";
    return tt;
   }

   else
   {
    tt=mystr;
    return tt;
   }
  }
  private static int Asc(String Mystr)
  {
   int inttemp;
   byte[] array = new byte[2];
   array = System.Text.Encoding.Default.GetBytes(Mystr);
   int i1 = (short)(array[0] - '/0');
   int i2 = (short)(array[1] - '/0');
   inttemp=Convert.ToInt32(i1.ToString() + i2.ToString());
   return inttemp;
  }  

 

//人民币小写转大写

public static string GetRMB(decimal myMoney)
  {
   string SHUZI;  //保存數字小寫
   string ZIFU;   //保存數字轉換后的結果
   int tmp1 ;  //臨時變量

   string[] shu=new String[14];
   string[] SHU1=new String[10];

   shu[13]= "仟";
   shu[12]= "佰";     shu[11]= "拾";     shu[10] ="億";
   shu[9] = "仟";     shu[8] = "佰";     shu[7] = "拾";
   shu[6] = "萬";     shu[5] = "仟";     shu[4] = "佰";
   shu[3] = "拾";     shu[2] = "元";     shu[1] = "角";
   shu[0] = "分";

   SHU1[0] = "零";    SHU1[1] = "壹";    SHU1[2] = "貳";
   SHU1[3] = "三";    SHU1[4] = "肆";    SHU1[5] = "伍";
   SHU1[6] = "陸";    SHU1[7] = "柒";    SHU1[8] = "捌";
   SHU1[9] = "玖";     
   
   //最大值為9999,9999,9999.99

   if(myMoney > Convert.ToDecimal(999999999999.99))//過大時返回原來值
   {
    return Convert.ToString(myMoney)+"元整";
   }
   else
   {
    SHUZI=Convert.ToString(myMoney*100);//先將數值轉化

    if (SHUZI.Substring(0,1)=="-")//為負數時去掉負號
    {
     SHUZI=SHUZI.Substring(1);
    }

    if(SHUZI.IndexOf(".")>0)//當小數位過兩位時,去掉小數位
    {
     SHUZI=SHUZI.Substring(0,SHUZI.IndexOf("."));
    }

    ZIFU = "";
    tmp1 = 0;  //從最首位開始轉化
    while(tmp1<SHUZI.Length)
    {
     if(SHUZI.Substring(tmp1,1) != "0")//當數字位不為零時,得到當前的 漢數 和 幣字
     {     
      ZIFU = ZIFU+SHU1[Convert.ToInt32(SHUZI.Substring(tmp1,1))]+shu[SHUZI.Length-tmp1-1];
     }

     else//當數字位不為零時
     {      
      if (tmp1==SHUZI.Length-3)//最未位的單位為 元
      {
       ZIFU = ZIFU+shu[2];
      }

      if (tmp1==SHUZI.Length-6) //以 萬 記
      {
       ZIFU = ZIFU+shu[6];
      }
      if (tmp1==SHUZI.Length-10)
      {
       ZIFU =ZIFU+shu[10];
      }
     }
     tmp1 = tmp1+1;
    }
   }
   return ZIFU+"整";
  }

原创粉丝点击