国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c# 中文轉拼音without CJK

2020-01-24 00:47:04
字體:
來源:轉載
供稿:網友

Xamarin寫Android程序時,通常要使用按中文首字母分組顯示(如通訊錄) 。

于是需要被迫包含CJK,不過包含后包肯定是會變大的,于是。。。。自己寫了一個硬枚舉的中文轉拼音的類。

原理是這樣的:

public class PinYinUtils{ private static readonly Dictionary<string, string> PinYinDict = new Dictionary<string, string> { {"猿", "YUAN"} // 等............ }; /// <summary> /// Return to the first letter /// </summary> /// <param name="word">Chinese word</param> /// <example> /// GetFirstPinyinChar("張三") /// will return "Z" /// Can be used for address book index and so on /// </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"></param> /// <example> /// GetPinYin('福') /// will return "FU" /// </example> /// <returns></returns> public static string GetPinYin(char chineseChar) { var str = chineseChar.ToString(); if (PinYinDict.ContainsKey(str)) {  return PinYinDict[str]; } return null; } /// <summary> /// Get the phonetic abbreviation for Chinese char /// </summary> /// <param name="chineseChar"></param> /// <example> /// GetShortPinYin('福') /// will return "F" /// </example> /// <returns></returns> public static string GetShortPinYin(char chineseChar) { var str = chineseChar.ToString(); if (PinYinDict.ContainsKey(str)) {  var first = PinYinDict[str].FirstOrDefault();  if (first == 0) return null;  return first.ToString(); } return null; }}

源碼:

https://github.com/chsword/PinYinUtil/blob/master/PinYinUtils.cs

GITHUB:https://github.com/chsword/PinYinUtil

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 噶尔县| 咸丰县| 比如县| 高碑店市| 扶沟县| 竹北市| 登封市| 嘉荫县| 郑州市| 贡嘎县| 米泉市| 宜兰市| 区。| 岚皋县| 丰原市| 洞头县| 宣化县| 雅安市| 彰武县| 黔南| 阿城市| 济阳县| 阿瓦提县| 吴江市| 靖西县| 临夏市| 正蓝旗| 孟津县| 新沂市| 炎陵县| 乐昌市| 乐至县| 合肥市| 江阴市| 冕宁县| 赞皇县| 宣城市| 湖北省| 镇宁| 体育| 河东区|