C#实现汉字拼音简码

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic;
 
 
namespace TrancePY
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write(" 请输入一连串汉字以回车键结束:" );
            string strHZ = Console.ReadLine();
            string strPY="";
            for (int i = 1; i < strHZ.Length+1; i++)
            {
                strPY += PYJM(Strings.Mid(strHZ, i, 1));
            }
            Console.Write(" 该系列汉字的拼音简码分别为:" + strPY+"/n");
        }
 
        static string PYJM(string strWord)
        {
 
            if (MyAsc(strWord)<0)
            {
                if (MyAsc(MyLeft(strWord,1))<MyAsc(" 啊" ))
                {
                    return "0";
                }
 
                if (MyAsc(MyLeft(strWord,1))>=MyAsc(" 啊" ) && MyAsc(MyLeft(strWord,1))<MyAsc(" 芭" ))
                {
                    return "A";
                }
 
                if (MyAsc(MyLeft(strWord,1))>=MyAsc(" 芭" ) && MyAsc(MyLeft(strWord,1))<MyAsc(" 擦" ))
                {
                    return "B";
                }
 
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 擦" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 搭" ))
                {
                    return "C";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 搭" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 蛾" ))
                {
                    return "D";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 蛾" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 发" ))
                {
                    return "E";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 发" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 噶" ))
                {
                    return "F";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 噶" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 哈" ))
                {
                    return "G";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 哈" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 击" ))
                {
                    return "H";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 击" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 喀" ))
                {
                    return "J";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 喀" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 垃" ))
                {
                    return "K";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 垃" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 妈" ))
                {
                    return "L";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 妈" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 拿" ))
                {
                    return "M";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 拿" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 哦" ))
                {
                    return "N";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 哦" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 啪" ))
                {
                    return "O";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 啪" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 期" ))
                {
                    return "P";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 期" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 然" ))
                {
                    return "Q";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 然" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 撒" ))
                {
                    return "R";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 撒" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 塌" ))
                {
                    return "S";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 塌" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 挖" ))
                {
                    return "T";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 挖" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 昔" ))
                {
                    return "W";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 昔" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 压" ))
                {
                    return "X";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 压" ) && MyAsc(MyLeft(strWord, 1)) < MyAsc(" 匝" ))
                {
                    return "Y";
                }
                if (MyAsc(MyLeft(strWord, 1)) >= MyAsc(" 匝" ))
                {
                    return "Z";
                }
                return "";
            }
            else
            {
                if (MyAsc(Strings.UCase(strWord))<= MyAsc("Z") && MyAsc(Strings.UCase(strWord)) >= MyAsc("A"))
                    return Strings.UCase(MyLeft(strWord, 1));
                else
                    return strWord;               
            }
        }
 
        static int MyAsc(string strS)
        {
            return Strings.Asc(strS);
        }
 
        static string MyLeft(string strS,int intLength)
        {
            return Strings.Left(strS, intLength);
        }
    }
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值