取中文拼音首字母,提供了多音字的选择 js javascript c# java(转)

第一个js版本
第二个C#版本
第三个也是C#版本
第四个java版本

第一个js版本

"Content-Type" content="text/html; charset=GB2312" /> <script language=> </script> <script language=> </script>

"0""8""center"
"800" cellspacing= cellpadding= align= >
"2" align="center">"tit">查看拼音首字母缩写程序
"20%" align="right">代码名称: "80%">查看拼音首字母缩写程序
"right">相关技术: JavaScript
"right">版本: "color:red">V1.01 修复了多音字中声母相同时出现冗余数据的问题
"right">功能说明: 一看一用就明白了.
"right">问题反馈: 如发现bug或者有改进意见请mail给我:[email protected],想骂我mail同上
"right">黑色头发: 做个小广告,我的blog地址,'http://heisetoufa.javaeye.com'>黑色头发
"right">375个异声母测试用例: 丁万且乐乘乜乾亟仇仡会传伺伽佃佚佴侗侥侧便俞俟倘傀其兹冯倘傀其兹冯凹刨券刹剡剿勺匙匹区卒单卡厂厕厦参句叨召叶吁合吓吡否吭呃呆呔呕呲呵咀咖咯咳哎哗哦唉唔唬啊喋喏喔喳

嗄嗌嗒嗳嘏嘘嘬嘲嘿噱嚣囝囤圈圜圩圻均坏坻垌埔埤堆堕堡塔壳夯夹奇契姥娩宿将尉尢尾尿屏属屯屹峒峙峤嵌巷帱幢广廑弄弹强彷忪恫恶悝慝戆戌戏扁扒扛扳折拂拗括拽挝挟挨捱掸掺提撮攒

於无暴曝曳曾朝期术杓枞枸柁柜查栅栎栖栝校桧椎椹楂楷槛欹歙殖氏汤沈沌沓沤泊泌泷泺浅浍浒浚涌涡渑湫溃溱漯澄澹瀑炅炔炮焘焯熬犍率玢町畜番疋疟瘕盛省瞧瞿矜石砉硌磅祢祭禅种秘稽

窨筠粘粥系繁繇红纤纥纶给绨缉缏缲缴翟耙脯腊腌膀臭般舵艾芒芘芥苎苕苣茄茈茜荑荠荤荥莞莩菀葚蔓蔚蕉藏藓虹虾蚵蛇蛤蛸蛾蜡蝤行衰袷裨裳褚覃见解识说诶调谷貉贾趄蹊蹲车轧辟适遗邪

郇酢重钯钿铅铛铤铫镐镡长阏阚阽阿陂降陶隗隹霰靓革鞘颈颉颌颤饧驮骀骠髟鬲魄鲭鸟鹄鹘麇鼽齐龈龟

"right">程序测试: 请输入中文字符串:"text" id="txtChinese" size="30" value="黑色头发"> "button" οnclick="query()" value="查看拼音首字母缩写">
"divResult">

第二个C#版本,这个相对来说代码量少一些

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace AllTest
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }


        /// 
        /// 汉字转拼音缩写
        /// /// 要转换的汉字字符串
        /// /// 
   
   
    
    拼音缩写
   
   
        public string GetPYString(string str)
        {
            string tempStr = "";
            foreach (char c in str)
            {
                if ((int)c >= 33 && (int)c <= 126)
                {
  //字母和符号原样保留           
                    tempStr += c.ToString();
                }
                else
                {
  //累加拼音声母     
                    tempStr += GetPYChar(c.ToString());
                }
            }
            return tempStr;
        }
        /// 
        /// /// 取单个字符的拼音声母/// Code By [email protected]
        /// /// 2004-11-30/// /// 要转换的单个汉字
        /// /// 
   
   
    
    拼音声母
   
   
        public string GetPYChar(string c)
        {
            byte[] array = new byte[2];
            array = System.Text.Encoding.Default.GetBytes(c);
            int i = (short)(array[0] - '/0') * 256 + ((short)(array[1] - '/0'));
            if (i < 0xB0A1) return "*";
            if (i < 0xB0C5) return "a";
            if (i < 0xB2C1) return "b";
            if (i < 0xB4EE) return "c";
            if (i < 0xB6EA) return "d";
            if (i < 0xB7A2) return "e";
            if (i < 0xB8C1) return "f";
            if (i < 0xB9FE) return "g";
            if (i < 0xBBF7) return "h";
            if (i < 0xBFA6) return "g";
            if (i < 0xC0AC) return "k";
            if (i < 0xC2E8) return "l";
            if (i < 0xC4C3) return "m";
            if (i < 0xC5B6) return "n";
            if (i < 0xC5BE) return "o";
            if (i < 0xC6DA) return "p";
            if (i < 0xC8BB) return "q";
            if (i < 0xC8F6) return "r";
            if (i < 0xCBFA) return "s";
            if (i < 0xCDDA) return "t";
            if (i < 0xCEF4) return "w";
            if (i < 0xD1B9) return "x";
            if (i < 0xD4D1) return "y";
            if (i < 0xD7FA) return "z";
            return "*";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = textBox1.Text+"的拼音缩写为:" + this.GetPYString(textBox1.Text);
        } 
    }
}

第三个也是C#版本,代码量稍多,但是可以取到汉字的拼音,而不只是首字母

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;



namespace AllTest
{
    /// 
    ///将汉字转换成为拼音
    /// 

    
    public partial class Form2: Form
    {
        public Form2()
        {
            InitializeComponent();
            MessageBox.Show("黑色头发转换为拼音后:"+Convert("黑色头发"));
        }

        private 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值