There are many Chinese character-to-PinYin conversion solutions on the Internet, but they do not know the performance and reliability. Therefore, based on the authoritative choice principle, I still want to find an official solution. The following is a practical Language Pack for Microsoft to convert Chinese characters to pinyin.
The installation package contains multiple languages, such as Japanese, Chinese, and Korean. Select to install CHSPinYinConv. msi. After that, you can reference ChnCharInfo. dll in the installation directory in the project.
The following is a demo of converting Chinese characters into pinyin.
Using Microsoft. international. converters. pinYinConverter; using System. collections. generic; using System. linq; using System. text; namespace Suspects. dll. util {publicclassPinYinUtil {// returns the publicstaticstring getSimplePinYin (stringinputTxt) {string shortR =; foreach (char cin inputTxt. trim () {ChineseChar chineseChar = newChineseChar (c); shortR + = chineseChar. pinyins [0]. substring (0, 1 ). toLower () ;}return shortR;} // returns the full publicstaticstring getAllPinYin (string inputTxt) {string allR =; foreach (char cin inputTxt. trim () {ChineseChar chineseChar = newChineseChar (c); allR + = chineseChar. pinyins [0]. substring (0, chineseChar. pinyins [0]. length-1 ). toLower () ;}return allR ;}}}