Code reference this article
Http://www.cnblogs.com/yazdao/archive/2011/06/04/2072488.html
VS2015 version
1. Install "simplifiedchinesepinyinconversion" using NuGet
2. Code:
usingMicrosoft.International.Converters.PinYinConverter;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacewindowsformsapplication2{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) { This. TextBox1.Text = Getpinyin ("You are my little apple.");//get full spell This. TextBox2.Text = Getfirstpinyin ("You are my little apple.");//Get first Letter } /// <summary> ///converting Chinese characters to pinyin/// </summary> /// <param name= "str" >Kanji</param> /// <returns>full Spell</returns> Public Static stringGetpinyin (stringstr) { stringR =string. Empty; foreach(CharObjinchstr) { Try{Chinesechar Chinesechar=NewChinesechar (obj); stringt = chinesechar.pinyins[0]. ToString (); R+ = T.substring (0, T.length-1); } Catch{R+=obj. ToString (); } } returnR; } /// <summary> ///convert Chinese characters to pinyin initials/// </summary> /// <param name= "str" >Kanji</param> /// <returns>First Letter</returns> Public Static stringGetfirstpinyin (stringstr) { stringR =string. Empty; foreach(CharObjinchstr) { Try{Chinesechar Chinesechar=NewChinesechar (obj); stringt = chinesechar.pinyins[0]. ToString (); R+ = T.substring (0,1); } Catch{R+=obj. ToString (); } } returnR; } }}
Effect:
C # uses Microsoft's Visual Studio International Pack Class Library to extract Chinese pinyin initials