获取汉字全拼以及首字母缩拼

合集下载

c#取汉字的拼音或拼音首字母

c#取汉字的拼音或拼音首字母
-18490, -18478, -18463, -18448, -18447, -18446, -18239, -18237, -18231, -18220, -18211, -18201, -18184, -18183, -18181, -18012,
-17997, -17988, -17970, -17964, -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, -17733, -17730, -17721, -17703,
-14645, -14630, -14594, -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353, -14345, -14170, -14159, -14151, -14149,
-14145, -14140, -14137, -14135, -14125, -14123, -14122, -14112, -14109, -14099, -14097, -14094, -14092, -14090, -14087, -14083,
}
public string GetAbbreviation(string strInput)
{
this.m_strInput = strInput;
this.GetPyCode();
return this.m_strAbbreviation;
}
num2 = buffer1[0];
if (num2 <= 0x7f)
{
this.m_strFullCode = this.m_strFullCode + chArray1[num4];

Java获取汉字拼音的全拼和首拼实现代码分享

Java获取汉字拼音的全拼和首拼实现代码分享

Java获取汉字拼⾳的全拼和⾸拼实现代码分享import java.util.Collections;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.Map;/*** 将汉字转化为全拼*/public class CnToSpell1 {private static Map<String, Integer> spellMap = null;//存放⽣僻字和其拼⾳的Mapprivate static Map<Character, String> uncommonWordsMap = null;static {if (spellMap == null) {spellMap = Collections.synchronizedMap(new LinkedHashMap<String, Integer>(396)) ;uncommonWordsMap = Collections.synchronizedMap(new LinkedHashMap<Character, String>(200)) ;}initialize();initUncommonWords();}private CnToSpell1() {}/*** 初始化*/private static void initialize() {spellMap.put("'a", -20319);spellMap.put("'ai", -20317);spellMap.put("'an", -20304);spellMap.put("'ang", -20295);spellMap.put("'ao", -20292);spellMap.put("ba", -20283);spellMap.put("bai", -20265);spellMap.put("ban", -20257);spellMap.put("bang", -20242);spellMap.put("bao", -20230);spellMap.put("bei", -20051);spellMap.put("ben", -20036);spellMap.put("beng", -20032);spellMap.put("bi", -20026);spellMap.put("bian", -20002);spellMap.put("biao", -19990);spellMap.put("bie", -19986);spellMap.put("bin", -19982);spellMap.put("bing", -19976);spellMap.put("bo", -19805);spellMap.put("bu", -19784);spellMap.put("ca", -19775);spellMap.put("cai", -19774);spellMap.put("can", -19763);spellMap.put("cang", -19756);spellMap.put("cao", -19751);spellMap.put("ce", -19746);spellMap.put("ceng", -19741);spellMap.put("cha", -19739);spellMap.put("chai", -19728);spellMap.put("chan", -19725);spellMap.put("chang", -19715);spellMap.put("chao", -19540);spellMap.put("che", -19531);spellMap.put("chen", -19525);spellMap.put("cheng", -19515);spellMap.put("chi", -19500);spellMap.put("chong", -19484);spellMap.put("chou", -19479);spellMap.put("chu", -19467);spellMap.put("chuai", -19289);spellMap.put("chuan", -19288);spellMap.put("chuang", -19281);spellMap.put("chui", -19275);spellMap.put("chun", -19270);spellMap.put("chuo", -19263);spellMap.put("ci", -19261);spellMap.put("cong", -19249);spellMap.put("cou", -19243);spellMap.put("dang", -19023); spellMap.put("dao", -19018); spellMap.put("de", -19006);spellMap.put("deng", -19003); spellMap.put("di", -18996);spellMap.put("dian", -18977); spellMap.put("diao", -18961); spellMap.put("die", -18952); spellMap.put("ding", -18783); spellMap.put("diu", -18774); spellMap.put("dong", -18773); spellMap.put("dou", -18763); spellMap.put("du", -18756);spellMap.put("duan", -18741); spellMap.put("dui", -18735); spellMap.put("dun", -18731); spellMap.put("duo", -18722); spellMap.put("'e", -18710);spellMap.put("'en", -18697);spellMap.put("'er", -18696);spellMap.put("fa", -18526);spellMap.put("fan", -18518); spellMap.put("fang", -18501); spellMap.put("fei", -18490);spellMap.put("fen", -18478); spellMap.put("feng", -18463); spellMap.put("fo", -18448);spellMap.put("fou", -18447); spellMap.put("fu", -18446);spellMap.put("ga", -18239);spellMap.put("gai", -18237); spellMap.put("gan", -18231); spellMap.put("gang", -18220); spellMap.put("gao", -18211); spellMap.put("ge", -18201);spellMap.put("gei", -18184); spellMap.put("gen", -18183); spellMap.put("geng", -18181); spellMap.put("gong", -18012); spellMap.put("gou", -17997); spellMap.put("gu", -17988);spellMap.put("gua", -17970); spellMap.put("guai", -17964); spellMap.put("guan", -17961); spellMap.put("guang", -17950); spellMap.put("gui", -17947); spellMap.put("gun", -17931); spellMap.put("guo", -17928); spellMap.put("ha", -17922);spellMap.put("hai", -17759); spellMap.put("han", -17752); spellMap.put("hang", -17733); spellMap.put("hao", -17730); spellMap.put("he", -17721);spellMap.put("hei", -17703); spellMap.put("hen", -17701); spellMap.put("heng", -17697); spellMap.put("hong", -17692); spellMap.put("hou", -17683); spellMap.put("hu", -17676);spellMap.put("hua", -17496); spellMap.put("huai", -17487); spellMap.put("huan", -17482); spellMap.put("huang", -17468); spellMap.put("hui", -17454); spellMap.put("hun", -17433); spellMap.put("huo", -17427); spellMap.put("ji", -17417);spellMap.put("jia", -17202);spellMap.put("jian", -17185); spellMap.put("jiang", -16983); spellMap.put("jiao", -16970); spellMap.put("jie", -16942);spellMap.put("jin", -16915);spellMap.put("jing", -16733); spellMap.put("jiong", -16708); spellMap.put("jiu", -16706);spellMap.put("ju", -16689);spellMap.put("ke", -16448);spellMap.put("ken", -16433); spellMap.put("keng", -16429); spellMap.put("kong", -16427); spellMap.put("kou", -16423); spellMap.put("ku", -16419);spellMap.put("kua", -16412); spellMap.put("kuai", -16407); spellMap.put("kuan", -16403); spellMap.put("kuang", -16401); spellMap.put("kui", -16393); spellMap.put("kun", -16220); spellMap.put("kuo", -16216); spellMap.put("la", -16212);spellMap.put("lai", -16205);spellMap.put("lan", -16202); spellMap.put("lang", -16187); spellMap.put("lao", -16180); spellMap.put("le", -16171);spellMap.put("lei", -16169);spellMap.put("leng", -16158); spellMap.put("li", -16155);spellMap.put("lia", -15959);spellMap.put("lian", -15958); spellMap.put("liang", -15944); spellMap.put("liao", -15933); spellMap.put("lie", -15920);spellMap.put("lin", -15915);spellMap.put("ling", -15903); spellMap.put("liu", -15889);spellMap.put("long", -15878); spellMap.put("lou", -15707); spellMap.put("lu", -15701);spellMap.put("lv", -15681);spellMap.put("luan", -15667); spellMap.put("lue", -15661); spellMap.put("lun", -15659); spellMap.put("luo", -15652); spellMap.put("ma", -15640); spellMap.put("mai", -15631); spellMap.put("man", -15625); spellMap.put("mang", -15454); spellMap.put("mao", -15448); spellMap.put("me", -15436); spellMap.put("mei", -15435); spellMap.put("men", -15419); spellMap.put("meng", -15416); spellMap.put("mi", -15408);spellMap.put("mian", -15394); spellMap.put("miao", -15385); spellMap.put("mie", -15377); spellMap.put("min", -15375); spellMap.put("ming", -15369); spellMap.put("miu", -15363); spellMap.put("mo", -15362); spellMap.put("mou", -15183); spellMap.put("mu", -15180); spellMap.put("na", -15165);spellMap.put("nai", -15158); spellMap.put("nan", -15153); spellMap.put("nang", -15150); spellMap.put("nao", -15149); spellMap.put("ne", -15144);spellMap.put("nei", -15143); spellMap.put("nen", -15141); spellMap.put("neng", -15140); spellMap.put("ni", -15139);spellMap.put("nian", -15128); spellMap.put("niang", -15121); spellMap.put("niao", -15119); spellMap.put("nie", -15117); spellMap.put("nin", -15110); spellMap.put("ning", -15109); spellMap.put("niu", -14941); spellMap.put("nong", -14937); spellMap.put("nu", -14933);spellMap.put("nv", -14930);spellMap.put("nuan", -14929);spellMap.put("pao", -14889);spellMap.put("pei", -14882);spellMap.put("pen", -14873);spellMap.put("peng", -14871); spellMap.put("pi", -14857);spellMap.put("pian", -14678); spellMap.put("piao", -14674); spellMap.put("pie", -14670);spellMap.put("pin", -14668);spellMap.put("ping", -14663); spellMap.put("po", -14654);spellMap.put("pu", -14645);spellMap.put("qi", -14630);spellMap.put("qia", -14594);spellMap.put("qian", -14429); spellMap.put("qiang", -14407); spellMap.put("qiao", -14399); spellMap.put("qie", -14384);spellMap.put("qin", -14379);spellMap.put("qing", -14368); spellMap.put("qiong", -14355); spellMap.put("qiu", -14353);spellMap.put("qu", -14345);spellMap.put("quan", -14170); spellMap.put("que", -14159);spellMap.put("qun", -14151);spellMap.put("ran", -14149);spellMap.put("rang", -14145); spellMap.put("rao", -14140);spellMap.put("re", -14137);spellMap.put("ren", -14135);spellMap.put("reng", -14125); spellMap.put("ri", -14123);spellMap.put("rong", -14122); spellMap.put("rou", -14112);spellMap.put("ru", -14109);spellMap.put("ruan", -14099); spellMap.put("rui", -14097);spellMap.put("run", -14094);spellMap.put("ruo", -14092);spellMap.put("sa", -14090);spellMap.put("sai", -14087);spellMap.put("san", -14083);spellMap.put("sang", -13917); spellMap.put("sao", -13914);spellMap.put("se", -13910);spellMap.put("sen", -13907);spellMap.put("seng", -13906); spellMap.put("sha", -13905);spellMap.put("shai", -13896); spellMap.put("shan", -13894); spellMap.put("shang", -13878); spellMap.put("shao", -13870); spellMap.put("she", -13859);spellMap.put("shen", -13847); spellMap.put("sheng", -13831); spellMap.put("shi", -13658);spellMap.put("shou", -13611); spellMap.put("shu", -13601);spellMap.put("shua", -13406); spellMap.put("shuai", -13404); spellMap.put("shuan", -13400); spellMap.put("shuang", -13398); spellMap.put("shui", -13395); spellMap.put("shun", -13391); spellMap.put("shuo", -13387); spellMap.put("si", -13383);spellMap.put("song", -13367); spellMap.put("sou", -13359);spellMap.put("su", -13356);spellMap.put("suan", -13343); spellMap.put("sui", -13340);spellMap.put("sun", -13329);spellMap.put("suo", -13326);spellMap.put("ta", -13318);spellMap.put("tai", -13147);spellMap.put("tan", -13138);spellMap.put("tang", -13120);spellMap.put("tong", -12888); spellMap.put("tou", -12875);spellMap.put("tu", -12871);spellMap.put("tuan", -12860); spellMap.put("tui", -12858);spellMap.put("tun", -12852);spellMap.put("tuo", -12849);spellMap.put("wa", -12838);spellMap.put("wai", -12831);spellMap.put("wan", -12829);spellMap.put("wang", -12812); spellMap.put("wei", -12802);spellMap.put("wen", -12607);spellMap.put("weng", -12597); spellMap.put("wo", -12594);spellMap.put("wu", -12585);spellMap.put("xi", -12556);spellMap.put("xia", -12359);spellMap.put("xian", -12346); spellMap.put("xiang", -12320); spellMap.put("xiao", -12300); spellMap.put("xie", -12120);spellMap.put("xin", -12099);spellMap.put("xing", -12089); spellMap.put("xiong", -12074); spellMap.put("xiu", -12067);spellMap.put("xu", -12058);spellMap.put("xuan", -12039); spellMap.put("xue", -11867);spellMap.put("xun", -11861);spellMap.put("ya", -11847);spellMap.put("yan", -11831);spellMap.put("yang", -11798); spellMap.put("yao", -11781);spellMap.put("ye", -11604);spellMap.put("yi", -11589);spellMap.put("yin", -11536);spellMap.put("ying", -11358); spellMap.put("yo", -11340);spellMap.put("yong", -11339); spellMap.put("you", -11324);spellMap.put("yu", -11303);spellMap.put("yuan", -11097); spellMap.put("yue", -11077);spellMap.put("yun", -11067);spellMap.put("za", -11055);spellMap.put("zai", -11052);spellMap.put("zan", -11045);spellMap.put("zang", -11041); spellMap.put("zao", -11038);spellMap.put("ze", -11024);spellMap.put("zei", -11020);spellMap.put("zen", -11019);spellMap.put("zeng", -11018); spellMap.put("zha", -11014);spellMap.put("zhai", -10838); spellMap.put("zhan", -10832); spellMap.put("zhang", -10815); spellMap.put("zhao", -10800); spellMap.put("zhe", -10790);spellMap.put("zhen", -10780); spellMap.put("zheng", -10764); spellMap.put("zhi", -10587);spellMap.put("zhong", -10544); spellMap.put("zhou", -10533); spellMap.put("zhu", -10519);spellMap.put("zhua", -10331); spellMap.put("zhuai", -10329); spellMap.put("zhuan", -10328); spellMap.put("zhuang", -10322); spellMap.put("zhui", -10315); spellMap.put("zhun", -10309); spellMap.put("zhuo", -10307); spellMap.put("zi", -10296);spellMap.put("zong", -10281); spellMap.put("zou", -10274);spellMap.put("zu", -10270);spellMap.put("zuan", -10262);/*** 添加⽣僻字* @param cnWord ⽣僻字* @param spell ⽣僻字的拼⾳, 如果拼⾳以 a, o ,e 开头,请将开头分别改为 'a, 'o, 'e,如:安('an) */public static void putUncommonWord(char cnWord, String spell){uncommonWordsMap.put(cnWord, spell);}/*** 初始化⽣僻字*/private static void initUncommonWords(){putUncommonWord('奡', "ao");putUncommonWord('灞', "ba");putUncommonWord('犇', "ben");putUncommonWord('猋', "biao");putUncommonWord('骉', "biao");putUncommonWord('杈', "cha");putUncommonWord('棽', "chen");putUncommonWord('琤', "cheng");putUncommonWord('魑', "chi");putUncommonWord('蟲', "chong");putUncommonWord('翀', "chong");putUncommonWord('麤', "cu");putUncommonWord('毳', "cui");putUncommonWord('昉', "fang");putUncommonWord('沣', "feng");putUncommonWord('玽', "gou");putUncommonWord('焓', "han");putUncommonWord('琀', "han");putUncommonWord('晗', "han");putUncommonWord('浛', "han");putUncommonWord('翮', "he");putUncommonWord('翯', "he");putUncommonWord('嬛', "huan");putUncommonWord('翙', "hui");putUncommonWord('劼', "jie");putUncommonWord('璟', "jing");putUncommonWord('誩', "jing");putUncommonWord('競', "jing");putUncommonWord('焜', "kun");putUncommonWord('琨', "kun");putUncommonWord('鹍', "kun");putUncommonWord('骊', "li");putUncommonWord('鎏', "liu");putUncommonWord('嫚', "man");putUncommonWord('槑', "mei");putUncommonWord('淼', "miao");putUncommonWord('婻', "nan");putUncommonWord('暔', "nan");putUncommonWord('甯', "ning");putUncommonWord('寗', "ning");putUncommonWord('掱', "pa");putUncommonWord('玭', "pi");putUncommonWord('汧', "qian");putUncommonWord('骎', "qin");putUncommonWord('甠', "qing");putUncommonWord('暒', "qing");putUncommonWord('凊', "qing");putUncommonWord('郬', "qing");putUncommonWord('靘', "qing");putUncommonWord('悫', "que");putUncommonWord('慤', "que");putUncommonWord('瑢', "rong");putUncommonWord('珅', "shen");putUncommonWord('屾', "shen");putUncommonWord('燊', "shen");putUncommonWord('焺', "sheng");putUncommonWord('珄', "sheng");putUncommonWord('晟', "sheng");putUncommonWord('昇', "sheng");putUncommonWord('眚', "sheng");putUncommonWord('湦', "sheng");putUncommonWord('陹', "sheng");putUncommonWord('竔', "sheng");putUncommonWord('琞', "sheng");putUncommonWord('湜', "shi");putUncommonWord('甦', "su");putUncommonWord('弢', "tao");putUncommonWord('瑱', "tian");putUncommonWord('沕', "wu");putUncommonWord('邬', "wu");putUncommonWord('晞', "xi");putUncommonWord('顕', "xian");putUncommonWord('婋', "xiao");putUncommonWord('虓', "xiao");putUncommonWord('筱', "xiao");putUncommonWord('勰', "xie");putUncommonWord('忻', "xin");putUncommonWord('庥', "xiu");putUncommonWord('媭', "xu");putUncommonWord('珝', "xu");putUncommonWord('昫', "xu");putUncommonWord('烜', "xuan");putUncommonWord('煊', "xuan");putUncommonWord('翾', "xuan");putUncommonWord('昍', "xuan");putUncommonWord('暄', "xuan");putUncommonWord('娅', "ya");putUncommonWord('琰', "yan");putUncommonWord('妍', "yan");putUncommonWord('焱', "yan");putUncommonWord('玚', "yang");putUncommonWord('旸', "yang");putUncommonWord('飏', "yang");putUncommonWord('垚', "yao");putUncommonWord('峣', "yao");putUncommonWord('怡', "yi");putUncommonWord('燚', "yi");putUncommonWord('晹', "yi");putUncommonWord('祎', "yi");putUncommonWord('瑛', "ying");putUncommonWord('煐', "ying");putUncommonWord('媖', "ying");putUncommonWord('暎', "ying");putUncommonWord('滢', "ying");putUncommonWord('锳', "ying");putUncommonWord('莜', "you");putUncommonWord('昱', "yu");putUncommonWord('沄', "yun");putUncommonWord('晢', "zhe");putUncommonWord('喆', "zhe");putUncommonWord('臸', "zhi");}/*** 获得单个汉字的Ascii.* @param cn 汉字字符* @return 汉字对应的 ascii, 错误时返回 0*/public static int getCnAscii(char cn) {byte[] bytes = (String.valueOf(cn)).getBytes();if (bytes == null || bytes.length == 0|| bytes.length > 2 ) { // 错误return 0;}if (bytes.length == 1) { // 英⽂字符return bytes[0];}if (bytes.length == 2) { // 中⽂字符int hightByte = 256 + bytes[0];int lowByte = 256 + bytes[1];return (256 * hightByte + lowByte) - 256 * 256; //返回 ASCII}return 0; // 错误}/*** 根据ASCII码到SpellMap中查找对应的拼⾳* @param ascii ASCII* @return ascii对应的拼⾳, 如果ascii对应的字符为单字符,则返回对应的单字符, 如果不是单字符且在 spellMap 中没找到对应的拼⾳,则返回空字符串(""), */public static String getSpellByAscii(int ascii) {if (ascii > 0 && ascii < 160) { // 单字符return String.valueOf((char) ascii);}if (ascii < -20319 || ascii > -10247) { // 不知道的字符return "";}String spell = null; //keyInteger asciiRang; //valueasciiRang = spellMap.get(spell); //拼⾳的ASCIIif(asciiRang != null){if (ascii >= asciiRangPrevious && ascii < asciiRang) { // 区间找到, 返回对应的拼⾳return (spellPrevious == null) ? spell : spellPrevious;} else {spellPrevious = spell;asciiRangPrevious = asciiRang;}}}return "";}/*** 获取字符串的全拼或⾸拼,是汉字则转化为对应的拼⾳或拼⾳⾸字母,其它字符不进⾏转换* @param cnStr 要获取全拼或⾸拼的字符串* @param onlyFirstSpell 是否只获取⾸拼,为true时,只获取⾸拼,为false时,获取全拼* @return String cnStr的全拼或⾸拼, 如果 cnStr 为null 时, 返回""*/public static String getSpell(String cnStr, boolean onlyFirstSpell) {if (cnStr == null) {return "";}char[] chars = cnStr.trim().toCharArray();StringBuffer sb = new StringBuffer();for (int i = 0, len = chars.length; i < len; i++) {int ascii = getCnAscii(chars[i]);if (ascii == 0){ //如果获取汉字的ASCII出错,则不进⾏转换sb.append(chars[i]);}else{String spell = getSpellByAscii(ascii); //根据ASCII取拼⾳if(spell == null || spell.length() == 0){ //如果根据ASCII取拼⾳没取到,则到⽣僻字Map中取spell = uncommonWordsMap.get(chars[i]);}if(spell == null || spell.length() == 0){ //如果没有取到对应的拼⾳,则不做转换,追加原字符spell = uncommonWordsMap.get(chars[i]);}else{if(onlyFirstSpell){sb.append(spell.startsWith("'") ? spell.substring(1, 2) : spell.substring(0, 1));}else{sb.append(spell);}}}} // end of forreturn sb.toString();}public static void main(String[] args) {String[] s = {"获取汉字全拼和⾸拼测试","This is a test","a,b; c[d]","标,点。

java根据汉字生成拼音全拼或拼音首字母的示例

java根据汉字生成拼音全拼或拼音首字母的示例

java根据汉字⽣成拼⾳全拼或拼⾳⾸字母的⽰例1.情景展⽰ java 根据中⽂⽣成对应的拼⾳2.准备⼯作 所需jar包:pinyin4j-2.5.0.jar 3.解决⽅案 导包import net.sourceforge.pinyin4j.PinyinHelper;import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; 代码实现/*** 根据汉字⽣成拼⾳全拼或拼⾳⾸字母* @explain* @author Marydon* @creationTime 2020年5⽉14⽇下午4:26:30* @version 1.0* @since* @email marydon20170307@*/public class GetPinyin {/*** 得到全拼* @param str* @return 全拼(⼩写)*/public static String getPinYin(String str){char t1[]=null;t1=str.toCharArray();String[] t2=new String[t1.length];HanyuPinyinOutputFormat t3=new HanyuPinyinOutputFormat();t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);t3.setVCharType(HanyuPinyinVCharType.WITH_V);String t4="";int t0=t1.length;try {for ( int i = 0; i < t0; i++ ) {//是⽤来判断是不是中⽂的⼀个条件,采⽤的是unicode编码if(Character.toString(t1[i]).matches("[\\u4E00-\\u9FA5]+")){t2= PinyinHelper.toHanyuPinyinStringArray(t1[i],t3);t4+=t2[0];}else {t4+=Character.toString(t1[i]);}}return t4;} catch ( BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination ) {badHanyuPinyinOutputFormatCombination.printStackTrace();}return t4;}/*** 得到汉字⾸字母的拼⾳* @param str* @return 拼⾳⾸字母(⼤写)*/public static String getPinYinHeaderChar(String str){String convert="";for ( int i = 0; i < str.length(); i++ ) {char word=str.charAt(i);String[] pinYinArray=PinyinHelper.toHanyuPinyinStringArray(word);if ( pinYinArray!=null ){convert+=pinYinArray[0].charAt(0);}else {convert+=word;}}return convert.toUpperCase();} //测试public static void main(String[] args) {System.out.println(getPinYin("⽕影忍者Marydon"));System.out.println(getPinYinHeaderChar("海贼王"));}}4.效果展⽰ 以上就是java 根据汉字⽣成拼⾳全拼或拼⾳⾸字母的⽰例的详细内容,更多关于Java 汉字⽣成拼⾳的资料请关注其它相关⽂章!。

C#汉字转换拼音简码和全拼音

C#汉字转换拼音简码和全拼音

C#汉字转换拼⾳简码和全拼⾳private static int[] pyValue = new int[]{-20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-20230,-20051,-20036,-20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-19775,-19774,-19763,-19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-19531,-19525,-19515,-19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-19263,-19261,-19249,-19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-19023,-19018,-19006,-19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-18756,-18741,-18735,-18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-18478,-18463,-18448,-18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-18183, -18181,-18012,-17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-17922,-17759,-17752,-17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-17496,-17487,-17482,-17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-16942,-16915,-16733,-16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-16459,-16452,-16448,-16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-16393,-16220,-16216,-16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-15959,-15958,-15944,-15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-15667,-15661,-15659,-15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-15416,-15408,-15394,-15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-15158,-15153,-15150,-15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-15117,-15110,-15109,-14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-14914,-14908,-14902,-14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-14668,-14663,-14654,-14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-14355,-14353,-14345,-14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-14123,-14122,-14112,-14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-13914,-13910,-13907,-13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-13658,-13611,-13601,-13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-13359,-13356,-13343,-13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076,-13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-12849,-12838,-12831,-12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-12346,-12320,-12300,-12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-11847,-11831,-11798,-11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-11097,-11077,-11067,-11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-11014,-10838,-10832,-10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,-10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-10260,-10256,-10254};private static string[] pyName = new string[]{"A","Ai","An","Ang","Ao","Ba","Bai","Ban","Bang","Bao","Bei","Ben", "Beng","Bi","Bian","Biao","Bie","Bin","Bing","Bo","Bu","Ba","Cai","Can", "Cang","Cao","Ce","Ceng","Cha","Chai","Chan","Chang","Chao","Che","Chen","Cheng", "Chi","Chong","Chou","Chu","Chuai","Chuan","Chuang","Chui","Chun","Chuo","Ci","Cong", "Cou","Cu","Cuan","Cui","Cun","Cuo","Da","Dai","Dan","Dang","Dao","De", "Deng","Di","Dian","Diao","Die","Ding","Diu","Dong","Dou","Du","Duan","Dui", "Dun","Duo","E","En","Er","Fa","Fan","Fang","Fei","Fen","Feng","Fo", "Fou","Fu","Ga","Gai","Gan","Gang","Gao","Ge","Gei","Gen","Geng","Gong", "Gou","Gu","Gua","Guai","Guan","Guang","Gui","Gun","Guo","Ha","Hai","Han", "Hang","Hao","He","Hei","Hen","Heng","Hong","Hou","Hu","Hua","Huai","Huan", "Huang","Hui","Hun","Huo","Ji","Jia","Jian","Jiang","Jiao","Jie","Jin","Jing", "Jiong","Jiu","Ju","Juan","Jue","Jun","Ka","Kai","Kan","Kang","Kao","Ke", "Ken","Keng","Kong","Kou","Ku","Kua","Kuai","Kuan","Kuang","Kui","Kun","Kuo", "La","Lai","Lan","Lang","Lao","Le","Lei","Leng","Li","Lia","Lian","Liang", "Liao","Lie","Lin","Ling","Liu","Long","Lou","Lu","Lv","Luan","Lue","Lun", "Luo","Ma","Mai","Man","Mang","Mao","Me","Mei","Men","Meng","Mi","Mian", "Miao","Mie","Min","Ming","Miu","Mo","Mou","Mu","Na","Nai","Nan","Nang", "Nao","Ne","Nei","Nen","Neng","Ni","Nian","Niang","Niao","Nie","Nin","Ning", "Niu","Nong","Nu","Nv","Nuan","Nue","Nuo","O","Ou","Pa","Pai","Pan", "Pang","Pao","Pei","Pen","Peng","Pi","Pian","Piao","Pie","Pin","Ping","Po", "Pu","Qi","Qia","Qian","Qiang","Qiao","Qie","Qin","Qing","Qiong","Qiu","Qu", "Quan","Que","Qun","Ran","Rang","Rao","Re","Ren","Reng","Ri","Rong","Rou", "Ru","Ruan","Rui","Run","Ruo","Sa","Sai","San","Sang","Sao","Se","Sen", "Seng","Sha","Shai","Shan","Shang","Shao","She","Shen","Sheng","Shi","Shou","Shu", "Shua","Shuai","Shuan","Shuang","Shui","Shun","Shuo","Si","Song","Sou","Su","Suan", "Sui","Sun","Suo","Ta","Tai","Tan","Tang","Tao","Te","Teng","Ti","Tian", "Tiao","Tie","Ting","Tong","Tou","Tu","Tuan","Tui","Tun","Tuo","Wa","Wai", "Wan","Wang","Wei","Wen","Weng","Wo","Wu","Xi","Xia","Xian","Xiang","Xiao", "Xie","Xin","Xing","Xiong","Xiu","Xu","Xuan","Xue","Xun","Ya","Yan","Yang", "Yao","Ye","Yi","Yin","Ying","Yo","Yong","You","Yu","Yuan","Yue","Yun","Za", "Zai","Zan","Zang","Zao","Ze","Zei","Zen","Zeng","Zha","Zhai","Zhan", "Zhang","Zhao","Zhe","Zhen","Zheng","Zhi","Zhong","Zhou","Zhu","Zhua","Zhuai","Zhuan", "Zhuang","Zhui","Zhun","Zhuo","Zi","Zong","Zou","Zu","Zuan","Zui","Zun","Zuo"};/// <summary>/// 从字符串中获取汉字拼⾳⾸字母,不是汉字则原样输出/// </summary>/// <param name="hz"></param>/// <returns></returns>public static string GetFirstPYLetter(string hz){string ls_second_eng = "CJWGNSPGCGNESYPBTYYZDXYKYGTDJNNJQMBSGZSCYJSYYQPGKBZGYCYWJKGKLJSWKPJQHYTWDDZLSGMRYPYWWCCKZNKYDGTTNGJEYKKZYTCJNMCYLQLYPYQFQRPZSLW +"HXMJJCJLXQGJMSHZKBSWYEMYLTXFSYDSGLYCJQXSJNQBSCTYHBFTDCYZDJWYGHQFRXWCKQKXEBPTLPXJZSRMEBWHJLBJSLYYSMDXLCLQKXLHXJRZJMFQHXHWYWSBHTRX +"JLYXYSYGLNSCMHCWWMNZJJLXXHCHSYDSTTXRYCYXBYHCSMXJSZNPWGPXXTAYBGAJCXLYSDCCWZOCWKCCSBNHCPDYZNFCYYTYCKXKYBSQKKYTQQXFCWCHCYKELZQBS + "SGXFZFCDKHJGXDLQFSGDSLQWZKXTMHSBGZMJZRGLYJBPMLMSXLZJQQHZYJCZYDJWBMJKLDDPMJEGXYHYLXHLQYQHKYCWCJMYYXNATJHYCCXZPCQLBZWWYTWBQCMLPMY +"BBSGGHFJLWPMZJNLYYWDQSHZXTYYWHMCYHYWDBXBTLMSYYYFSXJCSDXXLHJHFSSXZQHFZMZCZTQCXZXRTTDJHNNYZQQMNQDMMGYYDXMJGDHCDYZBFFALLZTDLTFXMXQ +"YTDKYXJYYCNRJMDJGKLCLJBCTBJDDBBLBLCZQRPXJCGLZCSHLTOLJNMDDDLNGKAQHQHJGYKHEZNMSHRPHQQJCHGMFPRXHJGDYCHGHLYRZQLCYQJNZSQTKQJYMSZ+ "ALBXYFBPNLSFHTGJWEJJXXGLLJSTGSHJQLZFKCGNNDSZFDEQFHBSAQTGLLBXMMYGSZLDYDQMJJRGBJTKGDHGKBLQKBDMBYLXWCXYTTYBKMRTJZXQJBHLMHMJJZMQASLDCY string ls_second_ch = "亍丌兀丐廿卅丕亘丞⿀孬噩⼁禺⼃⼔乇夭⽘卮氐囟胤馗毓睾鼗⼂亟" +"鼐乜乩亓芈孛啬嘏仄厍厝厣厥厮靥赝⼕叵匦匮匾赜卦卣刂刈刎刭刳刿剀剌剞剡剜蒯剽劂劁劐劓⼌罔亻仃仉仂仨仡仫仞伛仳伢佤仵伥伧伉伫佞佧攸佚佝佟佗伲伽佶佴侑侉侃侏佾佻侪佼侬侔俦俨俪俅俚俣俜俑俟俸倩偌俳倬倏倮倭俾倜倌倥倨偾偃偕偈偎偬偻傥傧傩傺僖儆僭僬僦僮儇儋仝氽佘佥俎⿕氽籴兮巽黉馘冁夔⼓匍訇匐凫夙兕⼇兖亳衮袤亵脔裒禀嬴蠃羸⼎冱冽冼凇⼍冢冥讠讦讧讪讴讵讷诂诃诋诏诎诒诓诔诖诘诙诜诟诠诤诨诩诮诰诳诶诹诼诿谀谂谄谇谌谏谑谒谔谕谖谙谛谘谝谟谠谡谥谧谪谫谮谯谲谳谵谶⼙卺阝阢阡阱阪阽阼" +"陂陉陔陟陧陬陲陴隈隍隗隰邗邛邝邙邬邡邴邳邶邺邸邰郏郅邾郐郄郇郓郦郢郜郗郛郫郯郾鄄鄢鄞鄣鄱鄯鄹酃酆刍奂劢劬劭劾哿勐勖勰叟燮矍⼵⼐凼⾿⼛弁畚巯坌垩垡塾墼壅壑圩圬圪圳圹圮圯坜圻坂坩垅坫垆坼坻坨坭坶坳垭垤垌垲埏垧垴垓垠埕埘埚埙埒垸埴埯埸埤埝堋堍埽埭堀堞堙塄堠塥塬墁墉墚墀馨鼙懿艹艽艿芏芊芨芄芎芑芗芙芫芸芾芰苈苊苣芘芷芮苋苌苁芩芴芡芪芟苄苎芤苡茉苷苤茏茇苜苴苒苘茌苻苓茑茚茆茔茕苠苕茜荑荛荜茈莒茼茴茱莛荞茯荏荇荃荟荀茗荠茭茺茳荦荥荨茛荩荬荪荭荮莰荸莳莴莠莪莓莜莅荼莶莩荽莸荻" +"莘莞莨莺莼菁萁菥菘堇萘萋菝菽菖萜萸萑萆菔菟萏萃菸菹菪菅菀萦菰菡葜葑葚葙葳蒇蒈葺蒉葸萼葆葩葶蒌蒎萱葭蓁蓍蓐蓦蒽蓓蓊蒿蒺蓠蒡蒹蒴蒗蓥蓣蔌甍蔸蓰蔹蔟蔺蕖蔻蓿蓼蕙蕈蕨蕤蕞蕺瞢蕃蕲蕻薤薨薇薏蕹薮薜薅薹薷薰藓藁藜藿蘧蘅蘩蘖蘼⼶弈夼奁耷奕奚奘匏⼪尥尬尴扌扪抟抻拊拚拗拮挢拶挹捋捃掭揶捱捺掎掴捭掬掊捩掮掼揲揸揠揿揄揞揎摒揆掾摅摁搋搛搠搌搦搡摞撄摭撖摺撷撸撙撺擀擐擗擤擢攉攥攮⼷忒甙弑卟叱叽叩叨叻吒吖吆呋呒呓呔呖呃吡呗呙吣吲咂咔呷呱呤咚咛咄呶呦咝哐咭哂咴哒咧咦哓哔呲咣哕咻咿哌哙哚哜咩" +"咪咤哝哏哞唛哧唠哽唔哳唢唣唏唑唧唪啧喏喵啉啭啁啕唿啐唼唷啖啵啶啷唳唰啜喋嗒喃喱喹喈喁喟啾嗖喑啻嗟喽喾喔喙嗪嗷嗉嘟嗑嗫嗬嗔嗦嗝嗄嗯嗥嗲嗳嗌嗍嗨嗵嗤辔嘞嘈嘌嘁嘤嘣嗾嘀嘧嘭噘嘹噗嘬噍噢噙噜噌噔嚆噤噱噫噻噼嚅嚓嚯囔⼞囝囡囵囫囹囿圄圊圉圜帏帙帔帑帱帻帼帷幄幔幛幞幡岌屺岍岐岖岈岘岙岑岚岜岵岢岽岬岫岱岣峁岷峄峒峤峋峥崂崃崧崦崮崤崞崆崛嵘崾崴崽嵬嵛嵯嵝嵫嵋嵊嵩嵴嶂嶙嶝豳嶷巅⼻彷徂徇徉後徕徙徜徨徭徵徼衢⼺犭犰犴犷犸狃狁狎狍狒狨狯狩狲狴狷猁狳猃狺狻猗猓猡猊猞猝猕猢猹猥猬猸猱獐獍獗獠獬獯獾" +"⾇夥飧夤⼡饣饧饨饩饪饫饬饴饷饽馀馄馇馊馍馐馑馓馔馕庀庑庋庖庥庠庹庵庾庳赓廒廑廛廨廪膺忄忉忖忏怃忮怄忡忤忾怅怆忪忭忸怙怵怦怛怏怍怩怫怊怿怡恸恹恻恺恂恪恽悖悚悭悝悃悒悌悛惬悻悱惝惘惆惚悴愠愦愕愣惴愀愎愫慊慵憬憔憧憷懔懵忝隳闩闫闱闳闵闶闼闾阃阄阆阈阊阋阌阍阏阒阕阖阗阙阚丬⽙戕氵汔汜汊沣沅沐沔沌汨汩汴汶沆沩泐泔沭泷泸泱泗沲泠泖泺泫泮沱泓泯泾洹洧洌浃浈洇洄洙洎洫浍洮洵洚浏浒浔洳涑浯涞涠浞涓涔浜浠浼浣渚淇淅淞渎涿淠渑淦淝淙渖涫渌涮渫湮湎湫溲湟溆湓湔渲渥湄滟溱溘滠漭滢溥溧溽溻溷滗溴滏溏滂" +"溟潢潆潇漤漕滹漯漶潋潴漪漉漩澉澍澌潸潲潼潺濑濉澧澹澶濂濡濮濞濠濯瀚瀣瀛瀹瀵灏灞⼧宄宕宓宥宸甯骞搴寤寮褰寰蹇謇辶迓迕迥迮迤迩迦迳迨逅逄逋逦逑逍逖逡逵逶逭逯遄遑遒遐遨遘遢遛暹遴遽邂邈邃邋⼹彗彖彘尻咫屐屙孱屣屦羼弪弩弭艴弼鬻⼬妁妃妍妩妪妣妗姊妫妞妤姒妲妯姗妾娅娆姝娈姣姘姹娌娉娲娴娑娣娓婀婧婊婕娼婢婵胬媪媛婷婺媾嫫媲嫒嫔媸嫠嫣嫱嫖嫦嫘嫜嬉嬗嬖嬲嬷孀尕尜孚孥孳孑孓孢驵驷驸驺驿驽骀骁骅骈骊骐骒骓骖骘骛骜骝骟骠骢骣骥骧纟纡纣纥纨纩纭纰纾绀绁绂绉绋绌绐绔绗绛绠绡绨绫绮绯绱绲缍绶绺绻绾缁缂缃" + "缇缈缋缌缏缑缒缗缙缜缛缟缡缢缣缤缥缦缧缪缫缬缭缯缰缱缲缳缵⼳畿⼮甾邕玎玑玮玢玟珏珂珑玷玳珀珉珈珥珙顼琊珩珧珞玺珲琏琪瑛琦琥琨琰琮琬琛琚瑁瑜瑗瑕瑙瑷瑭瑾璜璎璀璁璇璋璞璨璩璐璧瓒璺韪韫韬杌杓杞杈杩枥枇杪杳枘枧杵枨枞枭枋杷杼柰栉柘栊柩枰栌柙枵柚枳柝栀柃枸柢栎柁柽栲栳桠桡桎桢桄桤梃栝桕桦桁桧桀栾桊桉栩梵梏桴桷梓桫棂楮棼椟椠棹椤棰椋椁楗棣椐楱椹楠楂楝榄楫榀榘楸椴槌榇榈槎榉楦楣楹榛榧榻榫榭槔榱槁槊槟榕槠榍槿樯槭樗樘橥槲橄樾檠橐橛樵檎橹樽樨橘橼檑檐檩檗檫猷獒殁殂殇殄殒殓殍殚殛殡殪轫轭轱轲轳轵轶" +"轸轷轹轺轼轾辁辂辄辇辋辍辎辏辘辚軎戋戗戛戟戢戡戥戤戬臧瓯瓴瓿甏甑甓⽁旮旯旰昊昙杲昃昕昀炅曷昝昴昱昶昵耆晟晔晁晏晖晡晗晷暄暌暧暝暾曛曜曦曩贲贳贶贻贽赀赅赆赈赉赇赍赕赙觇觊觋觌觎觏觐觑牮犟牝牦牯牾牿犄犋犍犏犒挈挲掰搿擘耄毪毳毽毵毹氅氇氆氍氕氘氙氚氡氩氤氪氲攵敕敫牍牒牖爰虢刖肟肜肓肼朊肽肱肫肭肴肷胧胨胩胪胛胂胄胙胍胗朐胝胫胱胴胭脍脎胲胼朕脒豚脶脞脬脘脲腈腌腓腴腙腚腱腠腩腼腽腭腧塍媵膈膂膑滕膣膪臌朦臊膻臁膦欤欷欹歃歆歙飑飒飓飕飙飚⽎彀毂觳斐齑斓於旆旄旃旌旎旒旖炀炜炖炝炻烀炷炫炱烨烊焐焓焖焯焱" +"煳煜煨煅煲煊煸煺熘熳熵熨熠燠燔燧燹爝爨灬焘煦熹戾戽扃扈扉礻祀祆祉祛祜祓祚祢祗祠祯祧祺禅禊禚禧禳忑忐怼恝恚恧恁恙恣悫愆愍慝憩憝懋懑戆肀⾀沓泶淼矶矸砀砉砗砘砑斫砭砜砝砹砺砻砟砼砥砬砣砩硎硭硖硗砦硐硇硌硪碛碓碚碇碜碡碣碲碹碥磔磙磉磬磲礅磴礓礤礞礴龛⿋黻黼盱眄眍盹眇眈眚眢眙眭眦眵眸睐睑睇睃睚睨睢睥睿瞍睽瞀瞌瞑瞟瞠瞰瞵瞽町畀畎畋畈畛畲畹疃罘罡罟詈罨罴罱罹羁罾盍盥蠲钅钆钇钋钊钌钍钏钐钔钗钕钚钛钜钣钤钫钪钭钬钯钰钲钴钶钷钸钹钺钼钽钿铄铈铉铊铋铌铍铎铐铑铒铕铖铗铙铘铛铞铟铠铢铤铥铧铨铪铩铫铮铯铳铴铵铷铹铼" +"铽铿锃锂锆锇锉锊锍锎锏锒锓锔锕锖锘锛锝锞锟锢锪锫锩锬锱锲锴锶锷锸锼锾锿镂锵镄镅镆镉镌镎镏镒镓镔镖镗镘镙镛镞镟镝镡镢镤镥镦镧镨镩镪镫镬镯镱镲镳锺矧矬雉秕秭秣秫稆嵇稃稂稞稔稹稷穑黏馥穰皈皎皓皙皤瓞瓠甬鸠鸢鸨鸩鸪鸫鸬鸲鸱鸶鸸鸷鸹鸺鸾鹁鹂鹄鹆鹇鹈鹉鹋鹌鹎鹑鹕鹗鹚鹛鹜鹞鹣鹦鹧鹨鹩鹪鹫鹬鹱鹭鹳⽧疔疖疠疝疬疣疳疴疸痄疱疰痃痂痖痍痣痨痦痤痫痧瘃痱痼痿瘐瘀瘅瘌瘗瘊瘥瘘瘕瘙瘛瘼瘢瘠癀瘭瘰瘿瘵癃瘾瘳癍癞癔癜癖癫癯翊竦穸穹窀窆窈窕窦窠窬窨窭窳衤衩衲衽衿袂裆袷袼裉裢裎裣裥裱褚裼裨裾裰褡褙褓褛褊褴褫褶襁襦⽦胥皲皴矜⽾" +"耔耖耜耠耢耥耦耧耩耨耱耋耵聃聆聍聒聩聱覃顸颀颃颉颌颍颏颔颚颛颞颟颡颢颥颦⾌虔虬虮虿虺虼虻蚨蚍蚋蚬蚝蚧蚣蚪蚓蚩蚶蛄蚵蛎蚰蚺蚱蚯蛉蛏蚴蛩蛱蛲蛭蛳蛐蜓蛞蛴蛟蛘蛑蜃蜇蛸蜈蜊蜍蜉蜣蜻蜞蜥蜮蜚蜾蝈蜴蜱蜩蜷蜿螂蜢蝽蝾蝻蝠蝰蝌蝮螋蝓蝣蝼蝤蝙蝥螓螯螨蟒蟆螈螅螭螗螃螫蟥螬螵螳蟋蟓螽蟑蟀蟊蟛蟪蟠蟮蠖蠓蟾蠊蠛蠡蠹蠼⽸罂罄罅舐竺竽笈笃笄笕笊笫笏筇笸笪笙笮笱笠笥笤笳笾笞筘筚筅筵筌筝筠筮筻筢筲筱箐箦箧箸箬箝箨箅箪箜箢箫箴篑篁篌篝篚篥篦篪簌篾篼簏簖簋簟簪簦簸籁籀臾舁舂舄臬衄舡舢舣舭舯舨舫舸舻舳舴舾艄艉艋艏艚艟艨衾袅袈裘裟襞羝羟" +"羧羯羰羲籼敉粑粝粜粞粢粲粼粽糁糇糌糍糈糅糗糨⾉暨羿翎翕翥翡翦翩翮翳⽷絷綦綮繇纛麸麴赳趄趔趑趱赧赭豇豉酊酐酎酏酤酢酡酰酩酯酽酾酲酴酹醌醅醐醍醑醢醣醪醭醮醯醵醴醺⾗鹾趸跫踅蹙蹩趵趿趼趺跄跖跗跚跞跎跏跛跆跬跷跸跣跹跻跤踉跽踔踝踟踬踮踣踯踺蹀踹踵踽踱蹉蹁蹂蹑蹒蹊蹰蹶蹼蹯蹴躅躏躔躐躜躞⾘貂貊貅貘貔斛觖觞觚觜觥觫觯訾謦靓雩雳雯霆霁霈霏霎霪霭霰霾龀龃龅龆龇龈龉龊龌黾鼋鼍⾫隼隽雎雒瞿雠銎銮鋈錾鍪鏊鎏鐾鑫鱿鲂鲅鲆鲇鲈稣鲋鲎鲐鲑鲒鲔鲕鲚鲛鲞鲟鲠鲡鲢鲣鲥鲦鲧鲨鲩鲫鲭鲮鲰鲱鲲鲳鲴鲵鲶鲷鲺鲻鲼鲽鳄鳅鳆鳇鳊鳋鳌鳍鳎鳏鳐鳓鳔" + "鳕鳗鳘鳙鳜鳝鳟鳢靼鞅鞑鞒鞔鞯鞫鞣鞲鞴骱骰骷鹘骶骺骼髁髀髅髂髋髌髑魅魃魇魉魈魍魑飨餍餮饕饔⾽髡髦髯髫髻髭髹鬈鬏鬓鬟鬣麽麾縻麂麇麈麋麒鏖麝麟黛黜黝黠黟黢黩黧黥黪黯鼢鼬鼯鼹鼷鼽鼾齄";byte[] array = new byte[2];string return_py = "";for (int i = 0; i < hz.Length; i++){array = System.Text.Encoding.Default.GetBytes(hz[i].ToString());if (array[0] < 176) //.⾮汉字{return_py += hz[i];}else if (array[0] >= 176 && array[0] <= 215) //⼀级汉字{if (hz[i].ToString().CompareTo("匝") >= 0)return_py += "z";else if (hz[i].ToString().CompareTo("压") >= 0)return_py += "y";else if (hz[i].ToString().CompareTo("昔") >= 0)return_py += "x";else if (hz[i].ToString().CompareTo("挖") >= 0)return_py += "w";else if (hz[i].ToString().CompareTo("塌") >= 0)return_py += "t";else if (hz[i].ToString().CompareTo("撒") >= 0)return_py += "s";else if (hz[i].ToString().CompareTo("然") >= 0)return_py += "r";else if (hz[i].ToString().CompareTo("期") >= 0)return_py += "q";else if (hz[i].ToString().CompareTo("啪") >= 0)return_py += "p";else if (hz[i].ToString().CompareTo("哦") >= 0)return_py += "o";else if (hz[i].ToString().CompareTo("拿") >= 0)return_py += "n";else if (hz[i].ToString().CompareTo("妈") >= 0)return_py += "m";else if (hz[i].ToString().CompareTo("垃") >= 0)return_py += "l";else if (hz[i].ToString().CompareTo("喀") >= 0)return_py += "k";else if (hz[i].ToString().CompareTo("击") >= 0)return_py += "j";else if (hz[i].ToString().CompareTo("哈") >= 0)return_py += "h";else if (hz[i].ToString().CompareTo("噶") >= 0)return_py += "g";else if (hz[i].ToString().CompareTo("发") >= 0)return_py += "f";else if (hz[i].ToString().CompareTo("蛾") >= 0)return_py += "e";else if (hz[i].ToString().CompareTo("搭") >= 0)return_py += "d";else if (hz[i].ToString().CompareTo("擦") >= 0)return_py += "c";else if (hz[i].ToString().CompareTo("芭") >= 0)return_py += "b";else if (hz[i].ToString().CompareTo("啊") >= 0)return_py += "a";}else if (array[0] >= 215) //⼆级汉字{return_py += ls_second_eng.Substring(ls_second_ch.IndexOf(hz[i].ToString(), 0), 1); }}return return_py.ToLower();}/// <summary>/// 把汉字转换成拼⾳(全拼)/// </summary>/// <param name="hzString">汉字字符串</param>/// <returns>转换后的拼⾳(全拼)字符串</returns>public static string GetAllPYLetters(string hzString){// 匹配中⽂字符Regex regex = new Regex("^[\u4e00-\u9fa5]$");byte[] array = new byte[2];string pyString = "";int chrAsc = 0;int i1 = 0;int i2 = 0;char[] noWChar = hzString.ToCharArray();for (int j = 0; j < noWChar.Length; j++){// 中⽂字符if (regex.IsMatch(noWChar[j].ToString())){array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString());i1 = (short)(array[0]);i2 = (short)(array[1]);chrAsc = i1 * 256 + i2 - 65536;if (chrAsc > 0 && chrAsc < 160){pyString += noWChar[j];}else{// 修正部分⽂字if (chrAsc == -9254) // 修正“圳”字pyString += "Zhen";else{for (int i = (pyValue.Length - 1); i >= 0; i--){if (pyValue[i] <= chrAsc){pyString += pyName[i];break;}}}}}// ⾮中⽂字符else{pyString += noWChar[j].ToString();}}return pyString;}。

C# web 取汉字全拼或首字母拼音

C# web 取汉字全拼或首字母拼音
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region //gb2312中的汉字编码
//01-09区为特殊符号。
//16-55区为一级汉字,按拼音排序。
//56-87区为二级汉字,按部首/笔画排序。
// 每个汉字及符号以两个字节来表示。第一个字节称为“高位字节”,第二个字节称为“低位字节”。
using System;
using System.Data;
using System.Configuration;
using System.Text;
/// <summary>
/// qupy 的摘要说明
/// </summary>
public class qupy
{
public qupy()
new string[]{"ba","胈八吧巴叭扒朳叐灞欛矲軷釛癹炦拔抜罢魞釟蚆羓紦哵玐仈坺魃岜芭疤捌粑鲃茇笆霸跋鲅鼥把钯靶坝弝爸夿菝豝"},
new string[]{"bai","柏摆贁薭拝粨捭挀栢佰百白掰败拜稗竡"},
new string[]{"baike","兡"},
new string[]{"baiwa","瓸"},
new string[]{"chan","蝉鋋廛镡梴潺缠馋瀍禅刬孱谗婵辿谄韂羼颤忏繟冁镵阐蟾湹浐澶产鋓躔巉蒇摲幝簅搀灛讇幨铲嵼懴鄽毚磛劖棎硟嚵煘獑觇酁誗閳緾剷壥瀺掺纒艬旵丳潹"},
new string[]{"chang","娼伥昌场嚐韔唱鬯倡畅玚怅鋹氅敞鲳昶猖厂鲿嫦徜偿鋿尝苌肠阊菖惝畼淐常誯厰僘瑺鏛蟐椙晿瓺琩裮鼚兏锠"},

C++中获取汉字拼音首字缩写全拼及生僻字的处理

C++中获取汉字拼音首字缩写全拼及生僻字的处理

C++中获取汉字拼⾳⾸字缩写全拼及⽣僻字的处理 最近⼀直在修改关于搜索不到⽣僻字的问题,最后得出结论:对⽣僻字的处理,办法只有⼀个,建⽴⼀个字库,然后查表找。

1、关于⽣僻字的处理,加载⼀个汉字库,然后库中查找。

(仅适⽤于⽣僻字,频繁查询字库⽂件,会⾮常的慢)对于这种循环查询的⽅法,可能会把程序变慢,匹配度⼀般。

1 bool existFlag = false;2 if (firstPY.Find(strLowName) == -1 && util::existChinese(util::cStringToString(firstPY, CP_ACP)))//判断获得的⾸字拼⾳中是否还存在汉字,如果存在,说明有⽣僻字。

3 {4 std::vector<std::string> specialCharaterPy;5 module::getMiscModule()->GetSentencePinyin(util::cStringToString(RealName, CP_ACP), specialCharaterPy);//这⾥是查找汉字库,返回全拼。

6 CString Namepy;7 Namepy = util::stringToCString(specialCharaterPy.at(0));8 int count = 0;9 int findPos = 0;10 int startPos = 0;11 for (int i = 0; i < sShortName.GetLength(); i++)12 {13 findPos = Namepy.Find(sShortName[i], startPos);14 if (findPos == -1)15 {16 break;17 }18 else19 {20 count++;21 startPos = findPos + 1;//从查找到位置后+1继续寻找22 }23 }24 if (count != 0 && count == sShortName.GetLength())25 {26 existFlag = true;27 }28 } 2.⽣僻字的存储跟普通的汉⼦有所区别,贴⼀个找到汉字拼⾳缩写的代码(⽆法查找到⽣僻字,⽣僻字的两个⼀个⼤于160,⼀个⼩于160,会返回原汉字)。

excel获得汉字首字母的方法

excel获得汉字首字母的方法

在日常工作和学习中,我们经常需要对文本进行处理和分析,尤其是对于中文文本。

在处理中文文本时,有时会遇到需要将汉字转换为拼音的需求。

而在Excel中,获得汉字的首字母则成为了一个常见的需求。

那么,如何在Excel中获得汉字的首字母呢?我们可以利用Excel内置的函数来实现这一目标。

在Excel中,可以使用VB脚本编写一个自定义函数来获取汉字的首字母。

具体步骤如下:1. 打开Excel表格,按下ALT + F11,打开VB编辑器。

2. 在VB编辑器中,插入一个新模块。

3. 在新模块中输入以下VB脚本代码:```vbFunction GetFirstLetter(str As String) As StringDim pinyin As StringDim i As IntegerDim ch As Stringpinyin = ""For i = 1 To Len(str)ch = Mid(str, i, 1)pinyin = pinyin &Left(Application.WorksheetFunction.Phonetic(ch), 1)Next iGetFirstLetter = pinyinEnd Function```4. 编译保存后,返回Excel表格界面。

5. 在需要获取汉字首字母的单元格中输入`=GetFirstLetter(A1)`,其中A1为需要转换的汉字所在的单元格。

6. 按下Enter键,即可在目标单元格中获取到相应汉字的首字母。

通过上述方法,我们可以轻松地在Excel中获得汉字的首字母,而且可以将这个函数在多个单元格中批量应用,提高工作效率。

除了使用VB脚本自定义函数外,我们还可以借助Excel内置的函数来实现汉字首字母的获取。

在Excel中,有一个叫做UNICODE的函数,可以返回指定字符的Unicode编码。

而对于汉字来说,其首字母的Unicode编码可以作为其拼音的首字母。

Java获取中文拼音、中文首字母缩写和中文首字母的示例

Java获取中文拼音、中文首字母缩写和中文首字母的示例

Java获取中⽂拼⾳、中⽂⾸字母缩写和中⽂⾸字母的⽰例我们有时候会遇到这样的情况,需要获取某些中⽂的拼⾳、中⽂⾸字母缩写和中⽂⾸字母,下⾯我将为⼤家介绍⼀下如何获取中⽂拼⾳的缩写。

1、项⽬建⽴和配置⾸先,我们建⽴⼀个Java项⽬,新建libs⽂件夹并引⼊⼀个734a7099-4830-39f2-a136-0e850ccdcc7a.jar⽂件,这个步骤相信就不⽤详细写了,跳过。

2、获取中⽂拼⾳(如:⼴东省 -->guangdongsheng)</pre><pre name="code" class="java"><span style="white-space:pre"> </span>/*** 得到中⽂全拼* @param src 需要转化的中⽂字符串* @return*/public static String getPingYin(String src){char[] t1 = null;t1 = src.toCharArray();String[] t2 = new String[t1.length];HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);t3.setVCharType(HanyuPinyinVCharType.WITH_V);String t4 = "";int t0 = t1.length;try{for (int i = 0; i < t0; i++){// 判断是否为汉字字符if (ng.Character.toString(t1[i]).matches("[\\u4E00-\\u9FA5]+")){t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);t4 += t2[0];} else{t4 += ng.Character.toString(t1[i]);}}return t4;} catch (BadHanyuPinyinOutputFormatCombination e1){e1.printStackTrace();}return t4;}3、获取中⽂⾸字母缩写(如:⼴东省-->gds)</pre><pre name="code" class="java"><span style="white-space:pre"> </span>/*** 得到中⽂⾸字母* @param str 需要转化的中⽂字符串* @return*/public static String getPinYinHeadChar(String str){String convert = "";for (int j = 0; j < str.length(); j++){char word = str.charAt(j);String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);if (pinyinArray != null){convert += pinyinArray[0].charAt(0);} else{convert += word;}}return convert;}4、获取中⽂⾸字母并把转化为⼤写字母(如:⼴东省--> G)我们需要结合步骤3 getPinYinHeadChar⽅法,代码如下:</pre><pre name="code" class="java"><span style="white-space:pre"> </span>String s = getPinYinHeadChar("⼴东省"); System.out.println("得到拼⾳⾸字母缩写为:" + s);StringBuffer sb = new StringBuffer(s);if (sb.length() > 1){String ss = sb.delete(1, sb.length()).toString();System.out.println("得到的⾸字母为:"+ Character.toUpperCase(ss.toCharArray()[0]) + "");以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

汉字首字母提取函数公式

汉字首字母提取函数公式

汉字首字母提取函数公式
汉字首字母提取函数公式是用来将汉字转化为拼音首字母的数
学公式。

其主要思想是根据汉字的发音规律,将每个汉字的首字母提取出来,然后组成拼音首字母。

公式如下:
def get_first_letter(str):
result = ''
for s in str:
if s >= u'u4e00' and s <= u'u9fa5':
result += chr((ord(s) - 19968) // 676 + 65)
else:
result += s.upper()
return result
其中,参数str表示需要提取首字母的汉字字符串,函数首先定义一个空字符串result用于保存最终的结果。

然后,通过for循环遍历每个汉字,判断它是否在指定的Unicode范围内,如果是,则计算出它的首字母,并将其加入到结果中。

如果不是汉字,则直接将其转化为大写字母,并加入到结果中。

需要注意的是,该函数只适用于简体中文汉字,对于繁体中文或其他语言的汉字可能不适用。

此外,由于汉字的发音规律比较复杂,该函数的准确性也有限,需要根据具体情况进行调整。

- 1 -。

搜狗输入法全拼、简拼技巧

搜狗输入法全拼、简拼技巧

搜狗输入法全拼、简拼技巧
1,全拼
全拼输入是拼音输入法中最基本的输入方式。

你只要用Ctrl+Shift键切换到搜狗输入法,在输入窗口输入拼音即可输入。

然后依次选择你要字或词即可。

你可以用默认的翻页键是“逗号(,)句号(。

)”来进行翻页。

全拼模式:
2,简拼
简拼是输入声母或声母的首字母来进行输入的一种方式,有效的利用简拼,可以大大的提高输入的效率。

搜狗输入法现在支持的是声母简拼和声母的首字母简拼。

例如:你想输入“张靓颖”,你只要输入“zhly”或者“zly”都可以输入“张靓颖”。

同时,搜狗输入法支持简拼全拼的混合输入,例如:你输入“srf”“sruf”“shrfa”都是可以得到“输入法”的。

请注意:这里的声母的首字母简拼的作用和模糊音中的“z,s,c”相同。

但是,这属于两回事,即使你没有选择设置里的模糊音,你同样可以用“zly”可以输入“张靓颖”。

有效的用声母的首字母简拼可以提高输入效率,减少误打,例如,你输入“指示精神”这几个字,如果你输入传统的声母简拼,只能输入“zhshjsh”,需要输入的多而且多个h容易造成误打,而输入声母的首字母简拼,“zsjs”能很快得到你想要的词。

简拼模式1:
简拼模式2:
还有,简拼由于候选词过多,可以采用简拼和全拼混用的模式,这样能够兼顾最少输入字母和输入效率。

例如,你想输入“指示精神”你输入“zhishijs”、
“zsjingshen”、“zsjingsh”、“zsjingsh”“zsjings”都是可以的。

打字熟练的人会经常使用全拼和简拼混用的方式。

excel中提取汉字的拼音首字母

excel中提取汉字的拼音首字母
excel中提取汉字的拼音首字母
第一步:自定义函数。方法:按ALT+F11,在弹出窗口下,点击菜单栏里的“插入---模块”,在弹出的插入模块窗口中粘贴以下代码:
Function hztopy(hzpy As String) As String
Dim hzstring As String, pystring As String
Case &HD4D1 To &HD7F9: pystring = pystring + "Z"
Case Else
pystring = pystring + Mid(hzstring, hzi, 1)
End Select
Next
hztopy = pystring
Case &HB7A2 To &HB8C0: pystring = pystring + "F"
Case &HB8C1 To &HB9FD: pystring = pystring + "G"
Case &HB9FE To &HBBF6: pystring = pystring + "H"
Case &HC2E8 To &HC4C2: pystring = pystring + "M"
Case &HC4C3 To &HC5B5: pystring = pystring + "N"
Case &HC5B6 To &HC5BD: pystring = pystring + "O"

完美获取汉字拼音方法总结,包括获取各种生僻字难解字拼音

完美获取汉字拼音方法总结,包括获取各种生僻字难解字拼音

因为工作原因,需要用到汉字拼音,在网上也搜索了一些解决方法,但总是出现某些生僻字无法获取拼音的缺陷。

经过一些摸索之后找到两种解决方法:第一种:用一个较全的拼音汉字表然后自己编写获取拼音代码。

我是偶然找到一个好的拼音汉字表,估计是包括了所有的汉字生僻字。

该拼音汉字表可百度“汉字难解字及生僻字表与索引”查看。

然后我根据该拼音汉字索引表造了一个动态库,方法很简单,构造一个大的字符串指针数组,如下:static WCHAR * PinYins[][2] = {{L"a", L"啊阿呵吖嗄腌锕錒"},{L"ai", L"爱矮挨哎碍癌艾唉哀蔼隘埃皑呆嗌嫒瑷暧捱砹嗳锿霭乂乃伌僾儗凒剀剴叆呃呝啀嘊噫噯堨塧壒奇娭娾嬡嵦愛懓懝敱敳昹曖欬欸毐溰溾濭烠焥璦皚皧瞹硋磑礙絠薆藹諰譪譺賹躷醷鎄鑀閡阂阨阸隑靄靉餲馤騃鯦鱫鴱崖"},...};需要获取某个汉字的拼音时,直接遍历数组,用wcschr找到该汉字对应该位置,取出数组中的第一个拼音字符串指针就行了。

我已经写好详细的代码,省却了大家再去通过该“汉字难解字及生僻字表与索引”建立数组的过程了,下载地址:获取拼音源代码下载下面的实际的测试程序截图,像旸赟这些生僻字都可以获取到拼音的。

第二种:利用微软发布的 Microsoft Visual Studio International Pack 来获取汉字拼音。

这种方法是我最早应用在实际工作项目中的方法,用这个方法也可以获取各种生僻字的拼音,Microsoft Visual Studio International Pack 的具体内容可以百度“Microsoft Visual Studio International Pack“。

但用这种方法有个缺陷,因为我是用VC开发工具做的项目,打包时没法包含.NetFramework组件,而用这种方法需要.NetFramework的支持,因此还需要在用户的电脑上安装.NetFramework,我觉得这一点不够人性化,因为后来才琢磨了第一种方法。

使用PHP获取汉字的拼音(全部与首字母)

使用PHP获取汉字的拼音(全部与首字母)

使⽤PHP获取汉字的拼⾳(全部与⾸字母)废话不多说,直接上代码:复制代码代码如下:<?phpclass GetPingYing {private $pylist = array('a'=>-20319,'ai'=>-20317,'an'=>-20304,'ang'=>-20295,'ao'=>-20292,'ba'=>-20283,'bai'=>-20265,'ban'=>-20257,'bang'=>-20242,'bao'=>-20230,'bei'=>-20051,'ben'=>-20036,'beng'=>-20032,'bi'=>-20026,'bian'=>-20002,'biao'=>-19990,'bie'=>-19986,'bin'=>-19982,'bing'=>-19976,'bo'=>-19805,'bu'=>-19784,'ca'=>-19775,'cai'=>-19774,'can'=>-19763,'cang'=>-19756,'cao'=>-19751,'ce'=>-19746,'ceng'=>-19741,'cha'=>-19739,'chai'=>-19728,'chan'=>-19725,'chang'=>-19715,'chao'=>-19540,'che'=>-19531,'chen'=>-19525,'cheng'=>-19515,'chi'=>-19500,'chong'=>-19484,'chou'=>-19479,'chu'=>-19467,'chuai'=>-19289,'chuan'=>-19288,'chuang'=>-19281,'chui'=>-19275,'chun'=>-19270,'chuo'=>-19263,'ci'=>-19261,'cong'=>-19249,'cou'=>-19243,'dan'=>-19038, 'dang'=>-19023, 'dao'=>-19018, 'de'=>-19006,'deng'=>-19003, 'di'=>-18996,'dian'=>-18977, 'diao'=>-18961, 'die'=>-18952,'ding'=>-18783, 'diu'=>-18774,'dong'=>-18773, 'dou'=>-18763, 'du'=>-18756,'duan'=>-18741, 'dui'=>-18735,'dun'=>-18731, 'duo'=>-18722, 'e'=>-18710,'en'=>-18697,'er'=>-18696,'fa'=>-18526,'fan'=>-18518,'fang'=>-18501, 'fei'=>-18490,'fen'=>-18478,'feng'=>-18463, 'fo'=>-18448,'fou'=>-18447,'fu'=>-18446,'ga'=>-18239,'gai'=>-18237,'gan'=>-18231, 'gang'=>-18220, 'gao'=>-18211, 'ge'=>-18201,'gei'=>-18184,'gen'=>-18183, 'geng'=>-18181, 'gong'=>-18012, 'gou'=>-17997, 'gu'=>-17988,'gua'=>-17970, 'guai'=>-17964, 'guan'=>-17961, 'guang'=>-17950, 'gui'=>-17947,'gun'=>-17931, 'guo'=>-17928, 'ha'=>-17922,'hai'=>-17759,'han'=>-17752, 'hang'=>-17733, 'hao'=>-17730,'huai'=>-17487, 'huan'=>-17482, 'huang'=>-17468, 'hui'=>-17454,'hun'=>-17433, 'huo'=>-17427, 'ji'=>-17417,'jia'=>-17202,'jian'=>-17185, 'jiang'=>-16983, 'jiao'=>-16970, 'jie'=>-16942,'jin'=>-16915,'jing'=>-16733, 'jiong'=>-16708, 'jiu'=>-16706,'ju'=>-16689,'juan'=>-16664, 'jue'=>-16657,'jun'=>-16647,'ka'=>-16474,'kai'=>-16470,'kan'=>-16465, 'kang'=>-16459, 'kao'=>-16452, 'ke'=>-16448,'ken'=>-16433, 'keng'=>-16429, 'kong'=>-16427, 'kou'=>-16423, 'ku'=>-16419,'kua'=>-16412, 'kuai'=>-16407, 'kuan'=>-16403, 'kuang'=>-16401, 'kui'=>-16393,'kun'=>-16220, 'kuo'=>-16216, 'la'=>-16212,'lai'=>-16205,'lan'=>-16202,'lang'=>-16187, 'lao'=>-16180,'le'=>-16171,'lei'=>-16169,'leng'=>-16158, 'li'=>-16155,'lia'=>-15959,'lian'=>-15958, 'liang'=>-15944, 'liao'=>-15933, 'lie'=>-15920,'lin'=>-15915,'ling'=>-15903,'luo'=>-15652, 'ma'=>-15640, 'mai'=>-15631, 'man'=>-15625, 'mang'=>-15454, 'mao'=>-15448, 'me'=>-15436, 'mei'=>-15435, 'men'=>-15419, 'meng'=>-15416, 'mi'=>-15408,'mian'=>-15394, 'miao'=>-15385, 'mie'=>-15377, 'min'=>-15375, 'ming'=>-15369, 'miu'=>-15363, 'mo'=>-15362, 'mou'=>-15183, 'mu'=>-15180, 'na'=>-15165, 'nai'=>-15158, 'nan'=>-15153, 'nang'=>-15150, 'nao'=>-15149, 'ne'=>-15144, 'nei'=>-15143, 'nen'=>-15141, 'neng'=>-15140, 'ni'=>-15139,'nian'=>-15128, 'niang'=>-15121, 'niao'=>-15119, 'nie'=>-15117, 'nin'=>-15110, 'ning'=>-15109, 'niu'=>-14941, 'nong'=>-14937, 'nu'=>-14933, 'nv'=>-14930,'nuan'=>-14929, 'nue'=>-14928, 'nuo'=>-14926, 'o'=>-14922,'ou'=>-14921, 'pa'=>-14914, 'pai'=>-14908, 'pan'=>-14902, 'pang'=>-14894, 'pao'=>-14889, 'pei'=>-14882, 'pen'=>-14873, 'peng'=>-14871, 'pi'=>-14857,'qia'=>-14594,'qian'=>-14429, 'qiang'=>-14407, 'qiao'=>-14399, 'qie'=>-14384,'qin'=>-14379,'qing'=>-14368, 'qiong'=>-14355, 'qiu'=>-14353,'qu'=>-14345,'quan'=>-14170, 'que'=>-14159,'qun'=>-14151,'ran'=>-14149,'rang'=>-14145, 'rao'=>-14140,'re'=>-14137,'ren'=>-14135,'reng'=>-14125, 'ri'=>-14123,'rong'=>-14122, 'rou'=>-14112,'ru'=>-14109,'ruan'=>-14099, 'rui'=>-14097,'run'=>-14094,'ruo'=>-14092,'sa'=>-14090,'sai'=>-14087,'san'=>-14083,'sang'=>-13917, 'sao'=>-13914,'se'=>-13910,'sen'=>-13907,'seng'=>-13906, 'sha'=>-13905,'shai'=>-13896,'shan'=>-13894, 'shang'=>-13878, 'shao'=>-13870, 'she'=>-13859,'shen'=>-13847, 'sheng'=>-13831, 'shi'=>-13658,'shou'=>-13611, 'shu'=>-13601,'shua'=>-13406, 'shuai'=>-13404, 'shuan'=>-13400, 'shuang'=>-13398, 'shui'=>-13395,'shun'=>-13391, 'shuo'=>-13387, 'si'=>-13383,'tai'=>-13147, 'tan'=>-13138, 'tang'=>-13120, 'tao'=>-13107, 'te'=>-13096,'teng'=>-13095, 'ti'=>-13091,'tian'=>-13076, 'tiao'=>-13068, 'tie'=>-13063, 'ting'=>-13060, 'tong'=>-12888, 'tou'=>-12875, 'tu'=>-12871,'tuan'=>-12860, 'tui'=>-12858, 'tun'=>-12852, 'tuo'=>-12849, 'wa'=>-12838, 'wai'=>-12831, 'wan'=>-12829, 'wang'=>-12812, 'wei'=>-12802, 'wen'=>-12607, 'weng'=>-12597, 'wo'=>-12594, 'wu'=>-12585, 'xi'=>-12556,'xia'=>-12359, 'xian'=>-12346, 'xiang'=>-12320, 'xiao'=>-12300, 'xie'=>-12120, 'xin'=>-12099, 'xing'=>-12089, 'xiong'=>-12074, 'xiu'=>-12067, 'xu'=>-12058, 'xuan'=>-12039, 'xue'=>-11867, 'xun'=>-11861, 'ya'=>-11847, 'yan'=>-11831, 'yang'=>-11798, 'yao'=>-11781, 'ye'=>-11604, 'yi'=>-11589,'yin'=>-11536, 'ying'=>-11358, 'yo'=>-11340, 'yong'=>-11339, 'you'=>-11324, 'yu'=>-11303, 'yuan'=>-11097,'zei'=>-11020,'zen'=>-11019,'zeng'=>-11018,'zha'=>-11014,'zhai'=>-10838,'zhan'=>-10832,'zhang'=>-10815,'zhao'=>-10800,'zhe'=>-10790,'zhen'=>-10780,'zheng'=>-10764,'zhi'=>-10587,'zhong'=>-10544,'zhou'=>-10533,'zhu'=>-10519,'zhua'=>-10331,'zhuai'=>-10329,'zhuan'=>-10328,'zhuang'=>-10322,'zhui'=>-10315,'zhun'=>-10309,'zhuo'=>-10307,'zi'=>-10296,'zong'=>-10281,'zou'=>-10274,'zu'=>-10270,'zuan'=>-10262,'zui'=>-10260,'zun'=>-10256,'zuo'=>-10254);//全部拼⾳public function getAllPY($chinese, $delimiter = '', $length = 0) { $py = $this->zh_to_pys($chinese, $delimiter);if($length) {$py = substr($py, 0, $length);}return $py;}//拼⾳⾸个字母public function getFirstPY($chinese){$result = '' ;for ($i=0; $i<strlen($chinese); $i++) {$p = ord(substr($chinese,$i,1));if ($p>160) {$q = ord(substr($chinese,++$i,1));$p = $p*256 + $q - 65536;}$result .= substr($this->zh_to_py($p),0,1);}return $result ;}} elseif ($num<-20319||$num>-10247) {return $blank;} else {foreach ($this->pylist as $py => $code) {if($code > $num) break;$result = $py;}return $result;}}private function zh_to_pys($chinese, $delimiter = ' ', $first=0){$result = array();for($i=0; $i<strlen($chinese); $i++) {$p = ord(substr($chinese,$i,1));if($p>160) {$q = ord(substr($chinese,++$i,1));$p = $p*256 + $q - 65536;}$result[] = $this->zh_to_py($p);if ($first) {return $result[0];}}return implode($delimiter, $result);}}//-------------------------中⽂转拼⾳结束--------------------------------////中⽂是双字节,所以需要两个字节连接起来(ASCII码的范围是在161-255)$c = '齐秦';for($i=0; $i<strlen($c); $i++) {echo ord($c[$i]).' ';//198 235 199 216}echo '<br>',chr(198).chr(235).chr(199).chr(216),'<br>';//测试$PingYing = new GetPingYing();echo '<br>',$PingYing->getFirstPY('⽻泉乐队,歌不错-推荐'),'<br>';//yqldgbc-tjecho $PingYing->getAllPY('⽻泉乐队,歌不错-推荐'),'<br>'; //yuquanleduigebucuo-tuijian >。

获取汉字全拼以及首字母缩拼

获取汉字全拼以及首字母缩拼

获取汉字全拼以及首字母缩拼using System;using System.Collections.Generic;using System.Text;using System.Text.RegularExpressions;namespace mon.Tools{/// &lt;summary&gt;/// 汉字转拼音静态类,包括功能全拼和缩写,方法全部是静态的/// &lt;/summary&gt;public static class Chinese2Spell{#region 属性数据定义/// &lt;summary&gt;/// 汉字的机内码数组/// &lt;/summary&gt;private static int[] pyValue = new int[]{-20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-202 30,-20051,-20036,-20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-197 75,-19774,-19763,-19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-195 31,-19525,-19515,-19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-192 63,-19261,-19249,-19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-190 23,-19018,-19006,-19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-187 56,-18741,-18735,-18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-184 78,-18463,-18448,-18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-181 83, -18181,-18012,-17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-179 22,-17759,-17752,-17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-174 96,-17487,-17482,-17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-169 42,-16915,-16733,-16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-164 59,-16452,-16448,-16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-163 93,-16220,-16216,-16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-159 59,-15958,-15944,-15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-156 67,-15661,-15659,-15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-154 16,-15408,-15394,-15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-151 58,-15153,-15150,-15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-151 17,-15110,-15109,-14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-149 14,-14908,-14902,-14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-146 68,-14663,-14654,-14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-143 55,-14353,-14345,-14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-141 23,-14122,-14112,-14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-139 14,-13910,-13907,-13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-136 58,-13611,-13601,-13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-133 59,-13356,-13343,-13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076, -13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-128 49,-12838,-12831,-12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-123 46,-12320,-12300,-12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-118 47,-11831,-11798,-11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-110 97,-11077,-11067,-11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-110 14,-10838,-10832,-10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,-10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-102 60,-10256,-10254};/// &lt;summary&gt;/// 机内码对应的拼音数组/// &lt;/summary&gt;private static string[] pyName = new string[]{&quot;A&quot;,&quot;Ai&quot;,&quot;An&quot;,&quot;Ang&quot;,&q uot;Ao&quot;,&quot;Ba&quot;,&quot;Bai&quot;,&quot;Ban&quot;,&qu ot;Bang&quot;,&quot;Bao&quot;,&quot;Bei&quot;,&quot;Ben&quot;, &quot;Beng&quot;,&quot;Bi&quot;,&quot;Bian&quot;,&quot;Biao&quo t;,&quot;Bie&quot;,&quot;Bin&quot;,&quot;Bing&quot;,&quot;Bo&quot ;,&quot;Bu&quot;,&quot;Ba&quot;,&quot;Cai&quot;,&quot;Can&quot;, &quot;Cang&quot;,&quot;Cao&quot;,&quot;Ce&quot;,&quot;Ceng&quo t;,&quot;Cha&quot;,&quot;Chai&quot;,&quot;Chan&quot;,&quot;Chang &quot;,&quot;Chao&quot;,&quot;Che&quot;,&quot;Chen&quot;,&quot; Cheng&quot;,&quot;Chi&quot;,&quot;Chong&quot;,&quot;Chou&quot;,&quot;Chu&q uot;,&quot;Chuai&quot;,&quot;Chuan&quot;,&quot;Chuang&quot;,&qu ot;Chui&quot;,&quot;Chun&quot;,&quot;Chuo&quot;,&quot;Ci&quot;,&quot;Cong&quot;,&quot;Cou&quot;,&quot;Cu&quot;,&quot;Cuan&quot;,&quot;Cui&quot; ,&quot;Cun&quot;,&quot;Cuo&quot;,&quot;Da&quot;,&quot;Dai&quot; ,&quot;Dan&quot;,&quot;Dang&quot;,&quot;Dao&quot;,&quot;De&qu ot;,&quot;Deng&quot;,&quot;Di&quot;,&quot;Dian&quot;,&quot;Diao&qu ot;,&quot;Die&quot;,&quot;Ding&quot;,&quot;Diu&quot;,&quot;Dong& quot;,&quot;Dou&quot;,&quot;Du&quot;,&quot;Duan&quot;,&quot;Dui &quot;,&quot;Dun&quot;,&quot;Duo&quot;,&quot;E&quot;,&quot;En&quot;,& quot;Er&quot;,&quot;Fa&quot;,&quot;Fan&quot;,&quot;Fang&quot;,&q uot;Fei&quot;,&quot;Fen&quot;,&quot;Feng&quot;,&quot;Fo&quot;, &quot;Fou&quot;,&quot;Fu&quot;,&quot;Ga&quot;,&quot;Gai&quot;,& quot;Gan&quot;,&quot;Gang&quot;,&quot;Gao&quot;,&quot;Ge&quot; ,&quot;Gei&quot;,&quot;Gen&quot;,&quot;Geng&quot;,&quot;Gong&q uot;,&quot;Gou&quot;,&quot;Gu&quot;,&quot;Gua&quot;,&quot;Guai&quo t;,&quot;Guan&quot;,&quot;Guang&quot;,&quot;Gui&quot;,&quot;Gun &quot;,&quot;Guo&quot;,&quot;Ha&quot;,&quot;Hai&quot;,&quot;Han &quot;,&quot;Hang&quot;,&quot;Hao&quot;,&quot;He&quot;,&quot;Hei&quot ;,&quot;Hen&quot;,&quot;Heng&quot;,&quot;Hong&quot;,&quot;Hou&n&quot;,&quot;Huang&quot;,&quot;Hui&quot;,&quot;Hun&quot;,&quot;Huo&q uot;,&quot;Ji&quot;,&quot;Jia&quot;,&quot;Jian&quot;,&quot;Jiang&qu ot;,&quot;Jiao&quot;,&quot;Jie&quot;,&quot;Jin&quot;,&quot;Jing&quo t;,&quot;Jiong&quot;,&quot;Jiu&quot;,&quot;Ju&quot;,&quot;Juan&quot; ,&quot;Jue&quot;,&quot;Jun&quot;,&quot;Ka&quot;,&quot;Kai&quot;, &quot;Kan&quot;,&quot;Kang&quot;,&quot;Kao&quot;,&quot;Ke&quot; ,&quot;Ken&quot;,&quot;Keng&quot;,&quot;Kong&quot;,&quot;Kou&qu ot;,&quot;Ku&quot;,&quot;Kua&quot;,&quot;Kuai&quot;,&quot;Kuan& quot;,&quot;Kuang&quot;,&quot;Kui&quot;,&quot;Kun&quot;,&quot;Ku o&quot;,&quot;La&quot;,&quot;Lai&quot;,&quot;Lan&quot;,&quot;Lang&quot;, &quot;Lao&quot;,&quot;Le&quot;,&quot;Lei&quot;,&quot;Leng&quot;, &quot;Li&quot;,&quot;Lia&quot;,&quot;Lian&quot;,&quot;Liang&quot;, &quot;Liao&quot;,&quot;Lie&quot;,&quot;Lin&quot;,&quot;Ling&quot;, &quot;Liu&quot;,&quot;Long&quot;,&quot;Lou&quot;,&quot;Lu&quot;, &quot;Lv&quot;,&quot;Luan&quot;,&quot;Lue&quot;,&quot;Lun&quot;, &quot;Luo&quot;,&quot;Ma&quot;,&quot;Mai&quot;,&quot;Man&quot ;,&quot;Mang&quot;,&quot;Mao&quot;,&quot;Me&quot;,&quot;Mei&qn&quot;,&quot;Miao&quot;,&quot;Mie&quot;,&quot;Min&quot;,&quot;Ming&q uot;,&quot;Miu&quot;,&quot;Mo&quot;,&quot;Mou&quot;,&quot;Mu& quot;,&quot;Na&quot;,&quot;Nai&quot;,&quot;Nan&quot;,&quot;Nang &quot;,&quot;Nao&quot;,&quot;Ne&quot;,&quot;Nei&quot;,&quot;Nen&quot; ,&quot;Neng&quot;,&quot;Ni&quot;,&quot;Nian&quot;,&quot;Niang&q uot;,&quot;Niao&quot;,&quot;Nie&quot;,&quot;Nin&quot;,&quot;Ning &quot;,&quot;Niu&quot;,&quot;Nong&quot;,&quot;Nu&quot;,&quot;Nv&quot; ,&quot;Nuan&quot;,&quot;Nue&quot;,&quot;Nuo&quot;,&quot;O&quo t;,&quot;Ou&quot;,&quot;Pa&quot;,&quot;Pai&quot;,&quot;Pan&quot;, &quot;Pang&quot;,&quot;Pao&quot;,&quot;Pei&quot;,&quot;Pen&quot ;,&quot;Peng&quot;,&quot;Pi&quot;,&quot;Pian&quot;,&quot;Piao&qu ot;,&quot;Pie&quot;,&quot;Pin&quot;,&quot;Ping&quot;,&quot;Po&qu ot;,&quot;Pu&quot;,&quot;Qi&quot;,&quot;Qia&quot;,&quot;Qian&quot;, &quot;Qiang&quot;,&quot;Qiao&quot;,&quot;Qie&quot;,&quot;Qin&qu ot;,&quot;Qing&quot;,&quot;Qiong&quot;,&quot;Qiu&quot;,&quot;Qu &quot;,&quot;Quan&quot;,&quot;Que&quot;,&quot;Qun&quot;,&quot;Ran&quot;,&quot;Rang&quot;,&quot;Rao&quot;,&quot;Re&quot;,&quot;Ren& quot;,&quot;Reng&quot;,&quot;Ri&quot;,&quot;Rong&quot;,&quot;Rou &quot;,&quot;Ru&quot;,&quot;Ruan&quot;,&quot;Rui&quot;,&quot;Run&quot ;,&quot;Ruo&quot;,&quot;Sa&quot;,&quot;Sai&quot;,&quot;San&quot;, &quot;Sang&quot;,&quot;Sao&quot;,&quot;Se&quot;,&quot;Sen&quot; ,&quot;Seng&quot;,&quot;Sha&quot;,&quot;Shai&quot;,&quot;Shan&qu ot;,&quot;Shang&quot;,&quot;Shao&quot;,&quot;She&quot;,&quot;She n&quot;,&quot;Sheng&quot;,&quot;Shi&quot;,&quot;Shou&quot;,&quot;Shu&quot;,&quot;Shua&quot;,&quot;Shuai&quot;,&quot;Shuan&quot;,&quot;Shua ng&quot;,&quot;Shui&quot;,&quot;Shun&quot;,&quot;Shuo&quot;,&qu ot;Si&quot;,&quot;Song&quot;,&quot;Sou&quot;,&quot;Su&quot;,&quo t;Suan&quot;,&quot;Sui&quot;,&quot;Sun&quot;,&quot;Suo&quot;,&quot;Ta&quot;, &quot;Tai&quot;,&quot;Tan&quot;,&quot;Tang&quot;,&quot;Tao&quot; ,&quot;Te&quot;,&quot;Teng&quot;,&quot;Ti&quot;,&quot;Tian&quot;, &quot;Tiao&quot;,&quot;Tie&quot;,&quot;Ting&quot;,&quot;Tong&quot;,&quot;Tou&quot;,&quot;Tu&quot;,&quot;Tuan&quot;,&quot;Tui&quo t;,&quot;Tun&quot;,&quot;Tuo&quot;,&quot;Wa&quot;,&quot;Wai&qu ot;,&quot;Wan&quot;,&quot;Wang&quot;,&quot;Wei&quot;,&quot;Wen&q uot;,&quot;Weng&quot;,&quot;Wo&quot;,&quot;Wu&quot;,&quot;Xi& quot;,&quot;Xia&quot;,&quot;Xian&quot;,&quot;Xiang&quot;,&quot;Xia o&quot;,&quot;Xie&quot;,&quot;Xin&quot;,&quot;Xing&quot;,&quot;Xiong&quo t;,&quot;Xiu&quot;,&quot;Xu&quot;,&quot;Xuan&quot;,&quot;Xue&qu ot;,&quot;Xun&quot;,&quot;Ya&quot;,&quot;Yan&quot;,&quot;Yang&q uot;,&quot;Yao&quot;,&quot;Ye&quot;,&quot;Yi&quot;,&quot;Yin&quot;,&q uot;Ying&quot;,&quot;Yo&quot;,&quot;Yong&quot;,&quot;You&quot;,& quot;Yu&quot;,&quot;Yuan&quot;,&quot;Yue&quot;,&quot;Yun&quot;, &quot;Za&quot;,&quot;Zai&quot;,&quot;Zan&quot;,&quot;Zang&quot;,&quot;Zao&quot ;,&quot;Ze&quot;,&quot;Zei&quot;,&quot;Zen&quot;,&quot;Zeng&quot ;,&quot;Zha&quot;,&quot;Zhai&quot;,&quot;Zhan&quot;,&quot;Zhang&quot;,&quot;Zhao&quot;,&quot;Zhe&quot;,&quot;Zhen& quot;,&quot;Zheng&quot;,&quot;Zhi&quot;,&quot;Zhong&quot;,&quot; Zhou&quot;,&quot;Zhu&quot;,&quot;Zhua&quot;,&quot;Zhuai&quot;,& quot;Zhuan&quot;,&quot;Zhuang&quot;,&quot;Zhui&quot;,&quot;Zhun&quot;,&quot;Zhuo &quot;,&quot;Zi&quot;,&quot;Zong&quot;,&quot;Zou&quot;,&quot;Zu &quot;,&quot;Zuan&quot;,&quot;Zui&quot;,&quot;Zun&quot;,&quot;Zu o&quot;};#endregion#region 把汉字转换成拼音(全拼)无间隔符号/// &lt;summary&gt;/// 把汉字转换成拼音(全拼)/// &lt;/summary&gt;/// &lt;param name=&quot;hzString&quot;&gt;汉字字符串&lt;/param&gt;/// &lt;returns&gt;转换后的拼音(全拼)字符串&lt;/returns&gt;public static string Convert(string hzString){// 匹配中文字符Regex regex = new Regex(&quot;^[&quot;u4e00-&quot;u9fa5]$&quot;); byte[] array = new byte[2];string pyString = &quot;&quot;;int chrAsc = 0;int i1 = 0;int i2 = 0;char[] noWChar = hzString.ToCharArray();for (int j = 0; j &lt; noWChar.Length; j++){// 中文字符if (regex.IsMatch(noWChar[j].ToString())){array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString()); i1 = (short)(array[0]);i2 = (short)(array[1]);chrAsc = i1 * 256 + i2 - 65536;if (chrAsc &gt; 0 &amp;&amp; chrAsc &lt; 160){pyString += noWChar[j];}else{// 修正部分文字if (chrAsc == -9254) // 修正“圳”字pyString += &quot;Zhen&quot;;else{for (int i = (pyValue.Length - 1); i &gt;= 0; i--) {if (pyValue[i] &lt;= chrAsc){pyString += pyName[i];break;}}}}}// 非中文字符else{pyString += noWChar[j].ToString();}}return pyString;}#endregion#region 把汉字转换成拼音(全拼) 用空格间隔/// &lt;summary&gt;/// 把汉字转换成拼音(全拼)/// &lt;/summary&gt;/// &lt;param name=&quot;hzString&quot;&gt;汉字字符串&lt;/param&gt;/// &lt;returns&gt;转换后的拼音(全拼)字符串&lt;/returns&gt;public static string ConvertWithBlank(string hzString){// 匹配中文字符Regex regex = new Regex(&quot;^[&quot;u4e00-&quot;u9fa5]$&quot;); byte[] array = new byte[2];string pyString = &quot;&quot;;int chrAsc = 0;int i1 = 0;int i2 = 0;char[] noWChar = hzString.ToCharArray();for (int j = 0; j &lt; noWChar.Length; j++){// 中文字符if (regex.IsMatch(noWChar[j].ToString())){array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString()); i1 = (short)(array[0]);i2 = (short)(array[1]);chrAsc = i1 * 256 + i2 - 65536;if (chrAsc &gt; 0 &amp;&amp; chrAsc &lt; 160){pyString = pyString + &quot; &quot; + noWChar[j];}else{// 修正部分文字if (chrAsc == -9254) // 修正“圳”字pyString = pyString + &quot; &quot; + &quot;Zhen&quot;;else{for (int i = (pyValue.Length - 1); i &gt;= 0; i--)if (pyValue[i] &lt;= chrAsc){pyString = pyString + &quot; &quot; + pyName[i]; break;}}}}}// 非中文字符else{pyString = pyString +&quot; &quot;+ noWChar[j].ToString(); }}return pyString.Trim();}#endregion#region 把汉字转换成拼音(全拼) 用特定的字符间隔/// &lt;summary&gt;/// 把汉字转换成拼音(全拼)/// &lt;/summary&gt;/// &lt;param name=&quot;hzString&quot;&gt;汉字字符串&lt;/param&gt;/// &lt;returns&gt;转换后的拼音(全拼)字符串&lt;/returns&gt;public static string ConvertWithSplitChar(string hzString,string splitChar) {// 匹配中文字符Regex regex = new Regex(&quot;^[&quot;u4e00-&quot;u9fa5]$&quot;); byte[] array = new byte[2];string pyString = &quot;&quot;;int chrAsc = 0;int i1 = 0;int i2 = 0;char[] noWChar = hzString.ToCharArray();for (int j = 0; j &lt; noWChar.Length; j++)// 中文字符if (regex.IsMatch(noWChar[j].ToString())){array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString()); i1 = (short)(array[0]);i2 = (short)(array[1]);chrAsc = i1 * 256 + i2 - 65536;if (chrAsc &gt; 0 &amp;&amp; chrAsc &lt; 160){pyString = pyString + splitChar + noWChar[j];}else{// 修正部分文字if (chrAsc == -9254) // 修正“圳”字pyString = pyString + splitChar + &quot;Zhen&quot;;else{for (int i = (pyValue.Length - 1); i &gt;= 0; i--){if (pyValue[i] &lt;= chrAsc)pyString = pyString + splitChar + pyName[i];break;}}}}}// 非中文字符else{pyString = pyString + splitChar + noWChar[j].ToString(); }}char[] trimAChar = splitChar.ToCharArray();return pyString.TrimStart(trimAChar);}#endregion#region 汉字转拼音缩写(字符串) (小写)/// &lt;summary&gt;/// 汉字转拼音缩写/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringLower(string str){string tempStr = &quot;&quot;;foreach(char c in str){if((int)c &gt;= 33 &amp;&amp; (int)c &lt;=126){//字母和符号原样保留tempStr += c.ToString();}else{//累加拼音声母tempStr += GetSpellCharLower(c.ToString());}return tempStr;}#endregion#region 汉字转拼音缩写(字符串) (小写) (空格间隔)/// &lt;summary&gt;/// 汉字转拼音缩写(字符串) (小写) (空格间隔)/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringLowerSplitWithBlank(string str){string tempStr = &quot;&quot;;foreach (char c in str){if ((int)c &gt;= 33 &amp;&amp; (int)c &lt;= 126){//字母和符号原样保留tempStr = tempStr + &quot; &quot; + c.ToString();}else{//累加拼音声母tempStr = tempStr + &quot; &quot; + GetSpellCharLower(c.ToString()); }}return tempStr.Trim();}#endregion#region 汉字转拼音缩写(字符串)(大写)/// &lt;summary&gt;/// 汉字转拼音缩写(大写)/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringSupper(string str){string tempStr = &quot;&quot;;foreach (char c in str){if ((int)c &gt;= 33 &amp;&amp; (int)c &lt;= 126){//字母和符号原样保留tempStr += c.ToString();}else{//累加拼音声母tempStr += GetSpellCharSupper(c.ToString());}}return tempStr;}#endregion#region 汉字转拼音缩写(字符串)(大写)(空格间隔)/// &lt;summary&gt;/// 汉字转拼音缩写(字符串)(大写)(空格间隔)/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringSupperSplitWithBlank(string str){string tempStr = &quot;&quot;;foreach (char c in str){if ((int)c &gt;= 33 &amp;&amp; (int)c &lt;= 126){//字母和符号原样保留tempStr = tempStr + &quot; &quot; + c.ToString();}else{//累加拼音声母tempStr = tempStr + &quot; &quot; + GetSpellCharSupper(c.ToString()); }}return tempStr.Trim();}#endregion#region 取单个字符的拼音声母(字符)(大写)/// &lt;summary&gt;/// 取单个字符的拼音声母/// &lt;/summary&gt;/// &lt;param name=&quot;c&quot;&gt;要转换的单个汉字&lt;/param&gt;/// &lt;returns&gt;拼音声母&lt;/returns&gt;public static string GetSpellCharSupper(string c){byte[] array = new byte[2];array = System.Text.Encoding.Default.GetBytes(c);int i = (short)(array[0] - &#39;&quot;0&#39;) * 256 + ((short)(array[1] -&#39;&quot;0&#39;));if (i &lt; 0xB0A1) return c;if (i &lt; 0xB0C5) return &quot;A&quot;;if (i &lt; 0xB2C1) return &quot;B&quot;;if (i &lt; 0xB4EE) return &quot;C&quot;;if (i &lt; 0xB6EA) return &quot;D&quot;;if (i &lt; 0xB7A2) return &quot;E&quot;; if (i &lt; 0xB8C1) return &quot;F&quot;;if (i &lt; 0xB9FE) return &quot;G&quot;;if (i &lt; 0xBBF7) return &quot;H&quot;;if (i &lt; 0xBFA6) return &quot;J&quot;;if (i &lt; 0xC0AC) return &quot;K&quot;;if (i &lt; 0xC2E8) return &quot;L&quot;;if (i &lt; 0xC4C3) return &quot;M&quot;;if (i &lt; 0xC5B6) return &quot;N&quot;;if (i &lt; 0xC5BE) return &quot;O&quot;;if (i &lt; 0xC6DA) return &quot;P&quot;;if (i &lt; 0xC8BB) return &quot;Q&quot;;if (i &lt; 0xC8F6) return &quot;R&quot;;if (i &lt; 0xCBFA) return &quot;S&quot;;if (i &lt; 0xCDDA) return &quot;T&quot;;if (i &lt; 0xCEF4) return &quot;W&quot;;if (i &lt; 0xD1B9) return &quot;X&quot;;if (i &lt; 0xD4D1) return &quot;Y&quot;;if (i &lt; 0xD7FA) return &quot;Z&quot;;return c;}#endregion#region 取单个字符的拼音声母(字符)(小写)/// &lt;summary&gt;/// 取单个字符的拼音声母/// &lt;/summary&gt;/// &lt;param name=&quot;c&quot;&gt;要转换的单个汉字&lt;/param&gt;/// &lt;returns&gt;拼音声母&lt;/returns&gt;public static string GetSpellCharLower(string c){byte[] array = new byte[2];array = System.Text.Encoding.Default.GetBytes(c);int i = (short)(array[0] - &#39;&quot;0&#39;) * 256 + ((short)(array[1] - &#39;&quot;0&#39;));if (i &lt; 0xB0A1) return c;if (i &lt; 0xB0C5) return &quot;a&quot;;if (i &lt; 0xB2C1) return &quot;b&quot;;if (i &lt; 0xB4EE) return &quot;c&quot;;if (i &lt; 0xB6EA) return &quot;d&quot;;if (i &lt; 0xB7A2) return &quot;e&quot;;if (i &lt; 0xB8C1) return &quot;f&quot;;if (i &lt; 0xB9FE) return &quot;g&quot;;if (i &lt; 0xBBF7) return &quot;h&quot;;if (i &lt; 0xBFA6) return &quot;j&quot;;if (i &lt; 0xC0AC) return &quot;k&quot;;if (i &lt; 0xC2E8) return &quot;l&quot;;if (i &lt; 0xC4C3) return &quot;m&quot;;if (i &lt; 0xC5B6) return &quot;n&quot;;if (i &lt; 0xC5BE) return &quot;o&quot;;if (i &lt; 0xC6DA) return &quot;p&quot;;if (i &lt; 0xC8BB) return &quot;q&quot;; if (i &lt; 0xC8F6) return &quot;r&quot;; if (i &lt; 0xCBFA) return &quot;s&quot;; if (i &lt; 0xCDDA) return &quot;t&quot;; if (i &lt; 0xCEF4) return &quot;w&quot;; if (i &lt; 0xD1B9) return &quot;x&quot;; if (i &lt; 0xD4D1) return &quot;y&quot;; if (i &lt; 0xD7FA) return &quot;z&quot;; return c;}#endregion}}0 0 0(请您对文章做出评价)。

python获取一组汉字拼音首字母的方法

python获取一组汉字拼音首字母的方法

python获取⼀组汉字拼⾳⾸字母的⽅法本⽂实例讲述了python获取⼀组汉字拼⾳⾸字母的⽅法。

分享给⼤家供⼤家参考。

具体实现⽅法如下:#!/usr/bin/env python# -*- coding: utf-8 -*-def multi_get_letter(str_input):if isinstance(str_input, unicode):unicode_str = str_inputelse:try:unicode_str = str_input.decode('utf8')except:try:unicode_str = str_input.decode('gbk')except:print 'unknown coding'returnreturn_list = []for one_unicode in unicode_str:return_list.append(single_get_first(one_unicode))return return_listdef single_get_first(unicode1):str1 = unicode1.encode('gbk')try:ord(str1)return str1except:asc = ord(str1[0]) * 256 + ord(str1[1]) - 65536if asc >= -20319 and asc <= -20284:return 'a'if asc >= -20283 and asc <= -19776:return 'b'if asc >= -19775 and asc <= -19219:return 'c'if asc >= -19218 and asc <= -18711:return 'd'if asc >= -18710 and asc <= -18527:return 'e'if asc >= -18526 and asc <= -18240:return 'f'if asc >= -18239 and asc <= -17923:return 'g'if asc >= -17922 and asc <= -17418:return 'h'if asc >= -17417 and asc <= -16475:return 'j'if asc >= -16474 and asc <= -16213:return 'k'if asc >= -16212 and asc <= -15641:return 'l'if asc >= -15640 and asc <= -15166:return 'm'if asc >= -15165 and asc <= -14923:return 'n'if asc >= -14922 and asc <= -14915:return 'o'if asc >= -14914 and asc <= -14631:return 'p'if asc >= -14630 and asc <= -14150:return 'q'if asc >= -14149 and asc <= -14091:return 'r'if asc >= -14090 and asc <= -13119:return 's'if asc >= -13118 and asc <= -12839:return 't'if asc >= -12838 and asc <= -12557:return 'w'if asc >= -12556 and asc <= -11848:return 'x'if asc >= -11847 and asc <= -11056:return 'y'if asc >= -11055 and asc <= -10247:return 'z'return ''def main(str_input):a = multi_get_letter(str_input)b = ''for i in a:b= b+iprint bif __name__ == "__main__":str_input=u'欢迎你'main(str_input)希望本⽂所述对⼤家的Python程序设计有所帮助。

excel提取汉字的拼音首字母集锦

excel提取汉字的拼音首字母集锦

excel提取汉字的拼音首字母集锦方法一:(最完美的方法)如果你A列的汉字都在4个字符之内,那就在B列输入此公式:=LOOKUP(MID(A1,1,1),{"","";"吖","A";"八","B";"嚓","C";"咑","D";"鵽","E";"发","F";"猤","G";"铪","H";"夻","J";"咔","K";"垃","L";"嘸","M";"旀","N";"噢","O";"妑","P";"七","Q";"囕","R";"仨","S";"他","T";"屲","W";"夕","X";"丫","Y";"帀","Z"})&LOOKUP(MID(A1,2,1),{"","";"吖","A";"八","B";"嚓","C";"咑","D";"鵽","E";"发","F";"猤","G";"铪","H";"夻","J";"咔","K";"垃","L";"嘸","M";"旀","N";"噢","O";"妑","P";"七","Q";"囕","R";"仨","S";"他","T";"屲","W";"夕","X";"丫","Y";"帀","Z"})&LOOKUP(MID(A1,3,1),{"","";"吖","A";"八","B";"嚓","C";"咑","D";"鵽","E";"发","F";"猤","G";"铪","H";"夻","J";"咔","K";"垃","L";"嘸","M";"旀","N";"噢","O";"妑","P";"七","Q";"囕","R";"仨","S";"他","T";"屲","W";"夕","X";"丫","Y";"帀","Z"})&LOOKUP(MID(A1,4,1),{"","";"吖","A";"八","B";"嚓","C";"咑","D";"鵽","E";"发","F";"猤","G";"铪","H";"夻","J";"咔","K";"垃","L";"嘸","M";"旀","N";"噢","O";"妑","P";"七","Q";"囕","R";"仨","S";"他","T";"屲","W";"夕","X";"丫","Y";"帀","Z"})公式是长了一点,如果把{}里的数据定义为名称,可以转换更多的首字母具体方法:复制{}里的数据,插入-名称(或者按CTRL+F3),定义名称,如图,定义“拼音”为名称,下面的“引用位置”的“=”号后面粘贴刚才复制的{}里的数据确定。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

获取汉字全拼以及首字母缩拼using System;using System.Collections.Generic;using System.Text;using System.Text.RegularExpressions;namespace mon.Tools{/// &lt;summary&gt;/// 汉字转拼音静态类,包括功能全拼和缩写,方法全部是静态的/// &lt;/summary&gt;public static class Chinese2Spell{#region 属性数据定义/// &lt;summary&gt;/// 汉字的机内码数组/// &lt;/summary&gt;private static int[] pyValue = new int[]{-20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-202 30,-20051,-20036,-20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-197 75,-19774,-19763,-19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-195 31,-19525,-19515,-19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-192 63,-19261,-19249,-19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-190 23,-19018,-19006,-19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-187 56,-18741,-18735,-18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-184 78,-18463,-18448,-18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-181 83, -18181,-18012,-17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-179 22,-17759,-17752,-17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-174 96,-17487,-17482,-17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-169 42,-16915,-16733,-16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-164 59,-16452,-16448,-16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-163 93,-16220,-16216,-16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-159 59,-15958,-15944,-15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-156 67,-15661,-15659,-15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-154 16,-15408,-15394,-15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-151 58,-15153,-15150,-15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-151 17,-15110,-15109,-14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-149 14,-14908,-14902,-14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-146 68,-14663,-14654,-14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-143 55,-14353,-14345,-14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-141 23,-14122,-14112,-14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-139 14,-13910,-13907,-13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-136 58,-13611,-13601,-13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-133 59,-13356,-13343,-13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076, -13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-128 49,-12838,-12831,-12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-123 46,-12320,-12300,-12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-118 47,-11831,-11798,-11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-110 97,-11077,-11067,-11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-110 14,-10838,-10832,-10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,-10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-102 60,-10256,-10254};/// &lt;summary&gt;/// 机内码对应的拼音数组/// &lt;/summary&gt;private static string[] pyName = new string[]{&quot;A&quot;,&quot;Ai&quot;,&quot;An&quot;,&quot;Ang&quot;,&q uot;Ao&quot;,&quot;Ba&quot;,&quot;Bai&quot;,&quot;Ban&quot;,&qu ot;Bang&quot;,&quot;Bao&quot;,&quot;Bei&quot;,&quot;Ben&quot;, &quot;Beng&quot;,&quot;Bi&quot;,&quot;Bian&quot;,&quot;Biao&quo t;,&quot;Bie&quot;,&quot;Bin&quot;,&quot;Bing&quot;,&quot;Bo&quot ;,&quot;Bu&quot;,&quot;Ba&quot;,&quot;Cai&quot;,&quot;Can&quot;, &quot;Cang&quot;,&quot;Cao&quot;,&quot;Ce&quot;,&quot;Ceng&quo t;,&quot;Cha&quot;,&quot;Chai&quot;,&quot;Chan&quot;,&quot;Chang &quot;,&quot;Chao&quot;,&quot;Che&quot;,&quot;Chen&quot;,&quot; Cheng&quot;,&quot;Chi&quot;,&quot;Chong&quot;,&quot;Chou&quot;,&quot;Chu&q uot;,&quot;Chuai&quot;,&quot;Chuan&quot;,&quot;Chuang&quot;,&qu ot;Chui&quot;,&quot;Chun&quot;,&quot;Chuo&quot;,&quot;Ci&quot;,&quot;Cong&quot;,&quot;Cou&quot;,&quot;Cu&quot;,&quot;Cuan&quot;,&quot;Cui&quot; ,&quot;Cun&quot;,&quot;Cuo&quot;,&quot;Da&quot;,&quot;Dai&quot; ,&quot;Dan&quot;,&quot;Dang&quot;,&quot;Dao&quot;,&quot;De&qu ot;,&quot;Deng&quot;,&quot;Di&quot;,&quot;Dian&quot;,&quot;Diao&qu ot;,&quot;Die&quot;,&quot;Ding&quot;,&quot;Diu&quot;,&quot;Dong& quot;,&quot;Dou&quot;,&quot;Du&quot;,&quot;Duan&quot;,&quot;Dui &quot;,&quot;Dun&quot;,&quot;Duo&quot;,&quot;E&quot;,&quot;En&quot;,& quot;Er&quot;,&quot;Fa&quot;,&quot;Fan&quot;,&quot;Fang&quot;,&q uot;Fei&quot;,&quot;Fen&quot;,&quot;Feng&quot;,&quot;Fo&quot;, &quot;Fou&quot;,&quot;Fu&quot;,&quot;Ga&quot;,&quot;Gai&quot;,& quot;Gan&quot;,&quot;Gang&quot;,&quot;Gao&quot;,&quot;Ge&quot; ,&quot;Gei&quot;,&quot;Gen&quot;,&quot;Geng&quot;,&quot;Gong&q uot;,&quot;Gou&quot;,&quot;Gu&quot;,&quot;Gua&quot;,&quot;Guai&quo t;,&quot;Guan&quot;,&quot;Guang&quot;,&quot;Gui&quot;,&quot;Gun &quot;,&quot;Guo&quot;,&quot;Ha&quot;,&quot;Hai&quot;,&quot;Han &quot;,&quot;Hang&quot;,&quot;Hao&quot;,&quot;He&quot;,&quot;Hei&quot ;,&quot;Hen&quot;,&quot;Heng&quot;,&quot;Hong&quot;,&quot;Hou&n&quot;,&quot;Huang&quot;,&quot;Hui&quot;,&quot;Hun&quot;,&quot;Huo&q uot;,&quot;Ji&quot;,&quot;Jia&quot;,&quot;Jian&quot;,&quot;Jiang&qu ot;,&quot;Jiao&quot;,&quot;Jie&quot;,&quot;Jin&quot;,&quot;Jing&quo t;,&quot;Jiong&quot;,&quot;Jiu&quot;,&quot;Ju&quot;,&quot;Juan&quot; ,&quot;Jue&quot;,&quot;Jun&quot;,&quot;Ka&quot;,&quot;Kai&quot;, &quot;Kan&quot;,&quot;Kang&quot;,&quot;Kao&quot;,&quot;Ke&quot; ,&quot;Ken&quot;,&quot;Keng&quot;,&quot;Kong&quot;,&quot;Kou&qu ot;,&quot;Ku&quot;,&quot;Kua&quot;,&quot;Kuai&quot;,&quot;Kuan& quot;,&quot;Kuang&quot;,&quot;Kui&quot;,&quot;Kun&quot;,&quot;Ku o&quot;,&quot;La&quot;,&quot;Lai&quot;,&quot;Lan&quot;,&quot;Lang&quot;, &quot;Lao&quot;,&quot;Le&quot;,&quot;Lei&quot;,&quot;Leng&quot;, &quot;Li&quot;,&quot;Lia&quot;,&quot;Lian&quot;,&quot;Liang&quot;, &quot;Liao&quot;,&quot;Lie&quot;,&quot;Lin&quot;,&quot;Ling&quot;, &quot;Liu&quot;,&quot;Long&quot;,&quot;Lou&quot;,&quot;Lu&quot;, &quot;Lv&quot;,&quot;Luan&quot;,&quot;Lue&quot;,&quot;Lun&quot;, &quot;Luo&quot;,&quot;Ma&quot;,&quot;Mai&quot;,&quot;Man&quot ;,&quot;Mang&quot;,&quot;Mao&quot;,&quot;Me&quot;,&quot;Mei&qn&quot;,&quot;Miao&quot;,&quot;Mie&quot;,&quot;Min&quot;,&quot;Ming&q uot;,&quot;Miu&quot;,&quot;Mo&quot;,&quot;Mou&quot;,&quot;Mu& quot;,&quot;Na&quot;,&quot;Nai&quot;,&quot;Nan&quot;,&quot;Nang &quot;,&quot;Nao&quot;,&quot;Ne&quot;,&quot;Nei&quot;,&quot;Nen&quot; ,&quot;Neng&quot;,&quot;Ni&quot;,&quot;Nian&quot;,&quot;Niang&q uot;,&quot;Niao&quot;,&quot;Nie&quot;,&quot;Nin&quot;,&quot;Ning &quot;,&quot;Niu&quot;,&quot;Nong&quot;,&quot;Nu&quot;,&quot;Nv&quot; ,&quot;Nuan&quot;,&quot;Nue&quot;,&quot;Nuo&quot;,&quot;O&quo t;,&quot;Ou&quot;,&quot;Pa&quot;,&quot;Pai&quot;,&quot;Pan&quot;, &quot;Pang&quot;,&quot;Pao&quot;,&quot;Pei&quot;,&quot;Pen&quot ;,&quot;Peng&quot;,&quot;Pi&quot;,&quot;Pian&quot;,&quot;Piao&qu ot;,&quot;Pie&quot;,&quot;Pin&quot;,&quot;Ping&quot;,&quot;Po&qu ot;,&quot;Pu&quot;,&quot;Qi&quot;,&quot;Qia&quot;,&quot;Qian&quot;, &quot;Qiang&quot;,&quot;Qiao&quot;,&quot;Qie&quot;,&quot;Qin&qu ot;,&quot;Qing&quot;,&quot;Qiong&quot;,&quot;Qiu&quot;,&quot;Qu &quot;,&quot;Quan&quot;,&quot;Que&quot;,&quot;Qun&quot;,&quot;Ran&quot;,&quot;Rang&quot;,&quot;Rao&quot;,&quot;Re&quot;,&quot;Ren& quot;,&quot;Reng&quot;,&quot;Ri&quot;,&quot;Rong&quot;,&quot;Rou &quot;,&quot;Ru&quot;,&quot;Ruan&quot;,&quot;Rui&quot;,&quot;Run&quot ;,&quot;Ruo&quot;,&quot;Sa&quot;,&quot;Sai&quot;,&quot;San&quot;, &quot;Sang&quot;,&quot;Sao&quot;,&quot;Se&quot;,&quot;Sen&quot; ,&quot;Seng&quot;,&quot;Sha&quot;,&quot;Shai&quot;,&quot;Shan&qu ot;,&quot;Shang&quot;,&quot;Shao&quot;,&quot;She&quot;,&quot;She n&quot;,&quot;Sheng&quot;,&quot;Shi&quot;,&quot;Shou&quot;,&quot;Shu&quot;,&quot;Shua&quot;,&quot;Shuai&quot;,&quot;Shuan&quot;,&quot;Shua ng&quot;,&quot;Shui&quot;,&quot;Shun&quot;,&quot;Shuo&quot;,&qu ot;Si&quot;,&quot;Song&quot;,&quot;Sou&quot;,&quot;Su&quot;,&quo t;Suan&quot;,&quot;Sui&quot;,&quot;Sun&quot;,&quot;Suo&quot;,&quot;Ta&quot;, &quot;Tai&quot;,&quot;Tan&quot;,&quot;Tang&quot;,&quot;Tao&quot; ,&quot;Te&quot;,&quot;Teng&quot;,&quot;Ti&quot;,&quot;Tian&quot;, &quot;Tiao&quot;,&quot;Tie&quot;,&quot;Ting&quot;,&quot;Tong&quot;,&quot;Tou&quot;,&quot;Tu&quot;,&quot;Tuan&quot;,&quot;Tui&quo t;,&quot;Tun&quot;,&quot;Tuo&quot;,&quot;Wa&quot;,&quot;Wai&qu ot;,&quot;Wan&quot;,&quot;Wang&quot;,&quot;Wei&quot;,&quot;Wen&q uot;,&quot;Weng&quot;,&quot;Wo&quot;,&quot;Wu&quot;,&quot;Xi& quot;,&quot;Xia&quot;,&quot;Xian&quot;,&quot;Xiang&quot;,&quot;Xia o&quot;,&quot;Xie&quot;,&quot;Xin&quot;,&quot;Xing&quot;,&quot;Xiong&quo t;,&quot;Xiu&quot;,&quot;Xu&quot;,&quot;Xuan&quot;,&quot;Xue&qu ot;,&quot;Xun&quot;,&quot;Ya&quot;,&quot;Yan&quot;,&quot;Yang&q uot;,&quot;Yao&quot;,&quot;Ye&quot;,&quot;Yi&quot;,&quot;Yin&quot;,&q uot;Ying&quot;,&quot;Yo&quot;,&quot;Yong&quot;,&quot;You&quot;,& quot;Yu&quot;,&quot;Yuan&quot;,&quot;Yue&quot;,&quot;Yun&quot;, &quot;Za&quot;,&quot;Zai&quot;,&quot;Zan&quot;,&quot;Zang&quot;,&quot;Zao&quot ;,&quot;Ze&quot;,&quot;Zei&quot;,&quot;Zen&quot;,&quot;Zeng&quot ;,&quot;Zha&quot;,&quot;Zhai&quot;,&quot;Zhan&quot;,&quot;Zhang&quot;,&quot;Zhao&quot;,&quot;Zhe&quot;,&quot;Zhen& quot;,&quot;Zheng&quot;,&quot;Zhi&quot;,&quot;Zhong&quot;,&quot; Zhou&quot;,&quot;Zhu&quot;,&quot;Zhua&quot;,&quot;Zhuai&quot;,& quot;Zhuan&quot;,&quot;Zhuang&quot;,&quot;Zhui&quot;,&quot;Zhun&quot;,&quot;Zhuo &quot;,&quot;Zi&quot;,&quot;Zong&quot;,&quot;Zou&quot;,&quot;Zu &quot;,&quot;Zuan&quot;,&quot;Zui&quot;,&quot;Zun&quot;,&quot;Zu o&quot;};#endregion#region 把汉字转换成拼音(全拼)无间隔符号/// &lt;summary&gt;/// 把汉字转换成拼音(全拼)/// &lt;/summary&gt;/// &lt;param name=&quot;hzString&quot;&gt;汉字字符串&lt;/param&gt;/// &lt;returns&gt;转换后的拼音(全拼)字符串&lt;/returns&gt;public static string Convert(string hzString){// 匹配中文字符Regex regex = new Regex(&quot;^[&quot;u4e00-&quot;u9fa5]$&quot;); byte[] array = new byte[2];string pyString = &quot;&quot;;int chrAsc = 0;int i1 = 0;int i2 = 0;char[] noWChar = hzString.ToCharArray();for (int j = 0; j &lt; noWChar.Length; j++){// 中文字符if (regex.IsMatch(noWChar[j].ToString())){array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString()); i1 = (short)(array[0]);i2 = (short)(array[1]);chrAsc = i1 * 256 + i2 - 65536;if (chrAsc &gt; 0 &amp;&amp; chrAsc &lt; 160){pyString += noWChar[j];}else{// 修正部分文字if (chrAsc == -9254) // 修正“圳”字pyString += &quot;Zhen&quot;;else{for (int i = (pyValue.Length - 1); i &gt;= 0; i--) {if (pyValue[i] &lt;= chrAsc){pyString += pyName[i];break;}}}}}// 非中文字符else{pyString += noWChar[j].ToString();}}return pyString;}#endregion#region 把汉字转换成拼音(全拼) 用空格间隔/// &lt;summary&gt;/// 把汉字转换成拼音(全拼)/// &lt;/summary&gt;/// &lt;param name=&quot;hzString&quot;&gt;汉字字符串&lt;/param&gt;/// &lt;returns&gt;转换后的拼音(全拼)字符串&lt;/returns&gt;public static string ConvertWithBlank(string hzString){// 匹配中文字符Regex regex = new Regex(&quot;^[&quot;u4e00-&quot;u9fa5]$&quot;); byte[] array = new byte[2];string pyString = &quot;&quot;;int chrAsc = 0;int i1 = 0;int i2 = 0;char[] noWChar = hzString.ToCharArray();for (int j = 0; j &lt; noWChar.Length; j++){// 中文字符if (regex.IsMatch(noWChar[j].ToString())){array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString()); i1 = (short)(array[0]);i2 = (short)(array[1]);chrAsc = i1 * 256 + i2 - 65536;if (chrAsc &gt; 0 &amp;&amp; chrAsc &lt; 160){pyString = pyString + &quot; &quot; + noWChar[j];}else{// 修正部分文字if (chrAsc == -9254) // 修正“圳”字pyString = pyString + &quot; &quot; + &quot;Zhen&quot;;else{for (int i = (pyValue.Length - 1); i &gt;= 0; i--)if (pyValue[i] &lt;= chrAsc){pyString = pyString + &quot; &quot; + pyName[i]; break;}}}}}// 非中文字符else{pyString = pyString +&quot; &quot;+ noWChar[j].ToString(); }}return pyString.Trim();}#endregion#region 把汉字转换成拼音(全拼) 用特定的字符间隔/// &lt;summary&gt;/// 把汉字转换成拼音(全拼)/// &lt;/summary&gt;/// &lt;param name=&quot;hzString&quot;&gt;汉字字符串&lt;/param&gt;/// &lt;returns&gt;转换后的拼音(全拼)字符串&lt;/returns&gt;public static string ConvertWithSplitChar(string hzString,string splitChar) {// 匹配中文字符Regex regex = new Regex(&quot;^[&quot;u4e00-&quot;u9fa5]$&quot;); byte[] array = new byte[2];string pyString = &quot;&quot;;int chrAsc = 0;int i1 = 0;int i2 = 0;char[] noWChar = hzString.ToCharArray();for (int j = 0; j &lt; noWChar.Length; j++)// 中文字符if (regex.IsMatch(noWChar[j].ToString())){array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString()); i1 = (short)(array[0]);i2 = (short)(array[1]);chrAsc = i1 * 256 + i2 - 65536;if (chrAsc &gt; 0 &amp;&amp; chrAsc &lt; 160){pyString = pyString + splitChar + noWChar[j];}else{// 修正部分文字if (chrAsc == -9254) // 修正“圳”字pyString = pyString + splitChar + &quot;Zhen&quot;;else{for (int i = (pyValue.Length - 1); i &gt;= 0; i--){if (pyValue[i] &lt;= chrAsc)pyString = pyString + splitChar + pyName[i];break;}}}}}// 非中文字符else{pyString = pyString + splitChar + noWChar[j].ToString(); }}char[] trimAChar = splitChar.ToCharArray();return pyString.TrimStart(trimAChar);}#endregion#region 汉字转拼音缩写(字符串) (小写)/// &lt;summary&gt;/// 汉字转拼音缩写/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringLower(string str){string tempStr = &quot;&quot;;foreach(char c in str){if((int)c &gt;= 33 &amp;&amp; (int)c &lt;=126){//字母和符号原样保留tempStr += c.ToString();}else{//累加拼音声母tempStr += GetSpellCharLower(c.ToString());}return tempStr;}#endregion#region 汉字转拼音缩写(字符串) (小写) (空格间隔)/// &lt;summary&gt;/// 汉字转拼音缩写(字符串) (小写) (空格间隔)/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringLowerSplitWithBlank(string str){string tempStr = &quot;&quot;;foreach (char c in str){if ((int)c &gt;= 33 &amp;&amp; (int)c &lt;= 126){//字母和符号原样保留tempStr = tempStr + &quot; &quot; + c.ToString();}else{//累加拼音声母tempStr = tempStr + &quot; &quot; + GetSpellCharLower(c.ToString()); }}return tempStr.Trim();}#endregion#region 汉字转拼音缩写(字符串)(大写)/// &lt;summary&gt;/// 汉字转拼音缩写(大写)/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringSupper(string str){string tempStr = &quot;&quot;;foreach (char c in str){if ((int)c &gt;= 33 &amp;&amp; (int)c &lt;= 126){//字母和符号原样保留tempStr += c.ToString();}else{//累加拼音声母tempStr += GetSpellCharSupper(c.ToString());}}return tempStr;}#endregion#region 汉字转拼音缩写(字符串)(大写)(空格间隔)/// &lt;summary&gt;/// 汉字转拼音缩写(字符串)(大写)(空格间隔)/// &lt;/summary&gt;/// &lt;param name=&quot;str&quot;&gt;要转换的汉字字符串&lt;/param&gt;/// &lt;returns&gt;拼音缩写&lt;/returns&gt;public static string GetSpellStringSupperSplitWithBlank(string str){string tempStr = &quot;&quot;;foreach (char c in str){if ((int)c &gt;= 33 &amp;&amp; (int)c &lt;= 126){//字母和符号原样保留tempStr = tempStr + &quot; &quot; + c.ToString();}else{//累加拼音声母tempStr = tempStr + &quot; &quot; + GetSpellCharSupper(c.ToString()); }}return tempStr.Trim();}#endregion#region 取单个字符的拼音声母(字符)(大写)/// &lt;summary&gt;/// 取单个字符的拼音声母/// &lt;/summary&gt;/// &lt;param name=&quot;c&quot;&gt;要转换的单个汉字&lt;/param&gt;/// &lt;returns&gt;拼音声母&lt;/returns&gt;public static string GetSpellCharSupper(string c){byte[] array = new byte[2];array = System.Text.Encoding.Default.GetBytes(c);int i = (short)(array[0] - &#39;&quot;0&#39;) * 256 + ((short)(array[1] -&#39;&quot;0&#39;));if (i &lt; 0xB0A1) return c;if (i &lt; 0xB0C5) return &quot;A&quot;;if (i &lt; 0xB2C1) return &quot;B&quot;;if (i &lt; 0xB4EE) return &quot;C&quot;;if (i &lt; 0xB6EA) return &quot;D&quot;;if (i &lt; 0xB7A2) return &quot;E&quot;; if (i &lt; 0xB8C1) return &quot;F&quot;;if (i &lt; 0xB9FE) return &quot;G&quot;;if (i &lt; 0xBBF7) return &quot;H&quot;;if (i &lt; 0xBFA6) return &quot;J&quot;;if (i &lt; 0xC0AC) return &quot;K&quot;;if (i &lt; 0xC2E8) return &quot;L&quot;;if (i &lt; 0xC4C3) return &quot;M&quot;;if (i &lt; 0xC5B6) return &quot;N&quot;;if (i &lt; 0xC5BE) return &quot;O&quot;;if (i &lt; 0xC6DA) return &quot;P&quot;;if (i &lt; 0xC8BB) return &quot;Q&quot;;if (i &lt; 0xC8F6) return &quot;R&quot;;if (i &lt; 0xCBFA) return &quot;S&quot;;if (i &lt; 0xCDDA) return &quot;T&quot;;if (i &lt; 0xCEF4) return &quot;W&quot;;if (i &lt; 0xD1B9) return &quot;X&quot;;if (i &lt; 0xD4D1) return &quot;Y&quot;;if (i &lt; 0xD7FA) return &quot;Z&quot;;return c;}#endregion#region 取单个字符的拼音声母(字符)(小写)/// &lt;summary&gt;/// 取单个字符的拼音声母/// &lt;/summary&gt;/// &lt;param name=&quot;c&quot;&gt;要转换的单个汉字&lt;/param&gt;/// &lt;returns&gt;拼音声母&lt;/returns&gt;public static string GetSpellCharLower(string c){byte[] array = new byte[2];array = System.Text.Encoding.Default.GetBytes(c);int i = (short)(array[0] - &#39;&quot;0&#39;) * 256 + ((short)(array[1] - &#39;&quot;0&#39;));if (i &lt; 0xB0A1) return c;if (i &lt; 0xB0C5) return &quot;a&quot;;if (i &lt; 0xB2C1) return &quot;b&quot;;if (i &lt; 0xB4EE) return &quot;c&quot;;if (i &lt; 0xB6EA) return &quot;d&quot;;if (i &lt; 0xB7A2) return &quot;e&quot;;if (i &lt; 0xB8C1) return &quot;f&quot;;if (i &lt; 0xB9FE) return &quot;g&quot;;if (i &lt; 0xBBF7) return &quot;h&quot;;if (i &lt; 0xBFA6) return &quot;j&quot;;if (i &lt; 0xC0AC) return &quot;k&quot;;if (i &lt; 0xC2E8) return &quot;l&quot;;if (i &lt; 0xC4C3) return &quot;m&quot;;if (i &lt; 0xC5B6) return &quot;n&quot;;if (i &lt; 0xC5BE) return &quot;o&quot;;if (i &lt; 0xC6DA) return &quot;p&quot;;if (i &lt; 0xC8BB) return &quot;q&quot;; if (i &lt; 0xC8F6) return &quot;r&quot;; if (i &lt; 0xCBFA) return &quot;s&quot;; if (i &lt; 0xCDDA) return &quot;t&quot;; if (i &lt; 0xCEF4) return &quot;w&quot;; if (i &lt; 0xD1B9) return &quot;x&quot;; if (i &lt; 0xD4D1) return &quot;y&quot;; if (i &lt; 0xD7FA) return &quot;z&quot;; return c;}#endregion}}0 0 0(请您对文章做出评价)。

相关文档
最新文档