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

首頁 > 編程 > C# > 正文

c# 中文轉拼音without CJK

2019-10-29 21:14:24
字體:
來源:轉載
供稿:網友

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

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


注:相關教程知識閱讀請移步到c#教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巴南区| 兴国县| 涞源县| 绥芬河市| 湄潭县| 孟村| 静宁县| 吉首市| 桃园县| 中卫市| 西盟| 沂南县| 西林县| 公安县| 浮山县| 清镇市| 东台市| 同仁县| 罗江县| 常山县| 抚州市| 永德县| 太谷县| 浠水县| 会泽县| 阿克陶县| 宝清县| 乐安县| 宜宾市| 米易县| 北票市| 德清县| 长子县| 清水县| 永安市| 康马县| 前郭尔| 五台县| 甘孜| 梁河县| 安平县|