C # uses Microsoft's Visual Studio International Pack Class Library to extract Chinese pinyin initials

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.