C # chinese Pinyin without CJK code share

Source: Internet
Author: User
This article mainly introduced the Chinese pinyin without CJK, the article end attached source code download. Have a certain reference value, follow the small series below to see it

When Xamarin writes http://www.php.cn/wiki/1502.html "target=" _blank ">android program, it is usually used to group the first letter in Chinese (such as a correspondence record).

The need to be forced to include CJK, but the inclusion of the package will certainly become larger, so .... I wrote a hard enumeration of Chinese pinyin classes.

The principle is this:

public class pinyinutils{private static ReadOnly dictionary<string, string> pinyindict = new dictionary<string, string> {"Ape", "YUAN"}//etc....}; <summary>//Return to the first letter///</summary>/<param name= "word" >chinese Word</para m>//<example>//Getfirstpinyinchar ("Zhang San")///would return "Z"///Can be used for Address Book index and so O N//</example>//<returns></returns> public static string Getfirstpinyinchar (string word) {if (Word . Length = = 0) return "#"; var firstletter = word[0]. ToString (); if (Pinyindict.containskey (Firstletter)) {return pinyindict[firstletter];} return firstletter; }//<summary>//Return the Chinese char ' s pinyin///</summary>//<param name= "Chinesechar" ></p aram>//<example>//Getpinyin (' Fu ')///would return "FU"///</example>//<returns></returns& Gt public static string Getpinyin (char chinesechar) {varstr = chinesechar.tostring (); if (Pinyindict.containskey (str)) {return pinyindict[str];} return null; }///<summary>//Get the phonetic abbreviation for Chinese char///</summary>//<param name= "chinesec Har "></param>///<example>/Getshortpinyin (' Fu ')///would return" F "///</example>//<return s></returns> public static string Getshortpinyin (char chinesechar) {var str = chinesechar.tostring (); if (PinYin Dict.containskey (str)) {var first = Pinyindict[str].  FirstOrDefault ();  if (first = = 0) return null; return first. ToString (); } return null; }}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.