Sometimes the project will be based on the user's name pinyin retrieval data, Microsoft has provided a component installation package to handle non-English special language, called
Microsoft Visual Studio International Pack
Download this installation package, and then install the Simplified Chinese component
The default installation path is: C:\Program Files (x86) \microsoft Visual Studio International pack\simplified Chinese Pin-yin Conversion Library
To use this Kanji processing method in your project, you need to add the DLL files in that directory: ChnCharInfo.dll
Here are the methods available in this Simplified Chinese package
Test code:
usingMicrosoft.International.Converters.PinYinConverter;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceget Chinese Pinyin {classProgram {Static voidMain (string[] args) { //1. Get pinyin for a specified Chinese characterChinesechar cc =NewChinesechar ('le'); //because Chinese characters are likely to be polyphone, looping through the output of all pinyin foreach(varStrinchcc. Pinyins) {//the output is: Le4,yue4. (Note: Numbers on the back of Pinyin represent tones)Console.WriteLine (str); } //2. Get this kanji character. Console.WriteLine (CC. Chinesecharacter);//output: Le//3. Gets the number of strokes for this character. Console.WriteLine (CC. Strokenumber);//Output results: 5//4. Get the number of pinyin for this character. Console.WriteLine (CC. Pinyincount);//Output results: 2//5. Compare the number of strokes for the given character and the instance character. The number of strokes in the output as "le" minus the number of strokes of Chinese characters to compareConsole.WriteLine (Cc.comparestrokenumber ('in'));//"le" word strokes more than the "medium" word number of strokes more than 1, output results: 1Console.WriteLine (Cc.comparestrokenumber ('Master'));//The number of strokes in the "Le" word is as many as the number of strokes in the "main" word, output: 0Console.WriteLine (Cc.comparestrokenumber ('Country'));//"Guo" the number of strokes than "le" word number of strokes more than 3, output: -3//6. Retrieves the number of characters with the specified stroke count. Console.WriteLine (Chinesechar.getcharcount (1)); //7. Retrieves all strings with the specified number of strokes. Char[] Csamestrokenum = Chinesechar.getchars (1); foreach(varCinchcsamestrokenum) {Console.WriteLine (c); } //8. Gets all the phonetic characters for the given Ruby. Char[] Csamepinyin = Chinesechar.getchars ("Shao4");//PS: Must specify phonetic tones of pinyin foreach(varCinchCsamepinyin) {Console.WriteLine (c); } //9. There are many other waysConsole.readkey (); } }}
View Code
Kanji Processing Components