C # use Microsoft's Visual Studio International pack class library to extract the first letter of Chinese pinyin

Source: Internet
Author: User


Yesterday, a user reminded me that the method for extracting Chinese characters and pinyin can use Microsoft's class library Visual Studio International pack. Today I tried it and it is really easy to use! The usage is as follows:




First download Visual Studio International pack 1.0, official: http://www.microsoft.com/downloads/zh-cn/details.aspx? Familyid = 44cac7f0-633b-477d-aed2-99aee642fc10 & displaylang = ZH-CN. After downloading, decompress the package. After unzipping the package, you can find seven MSI installation files, including chspinyinconv. MSI is a Chinese pinyin component, chtchsconv. MSI is a simplified and simplified conversion component. you can install these two MSI (the default installation directory on the x86 operating system is c: \ Program Files \Microsoft Visual Studio International pack\). After the installation is complete, you need to add references in vs to reference them separately:C: \ Program Files \ Microsoft Visual Studio International pack \ Simplified Chinese pin-yin conversion Library(Pinyin) andC: \ Program Files \ Microsoft Visual Studio International pack \ traditional Chinese to simplified Chinese conversion library and add-in tool(Simple and easy to use.




After completing the above work, the usage is very simple. See belowCode:



 


Using Microsoft. International. converters. pinyinconverter; // Import pinyin

Namespace Webapplication2
{
Public   Class Class1
{
///   <Summary>  
/// Converting Chinese characters to PinYin
///   </Summary>  
///   <Param name = "str"> Chinese characters </Param>  
///   <Returns> Full competition </Returns>  
Public   Static   String Getpinyin ( String Str)
{
String R =   String . Empty;
Foreach ( Char OBJ In Str)
{
Try
{
Chinesechar =   New Chinesechar (OBJ );
String T = Chinesechar. pinyins [ 0 ]. Tostring ();
R + = T. substring ( 0 , T. Length -   1 );
}
Catch
{
R + = OBJ. tostring ();
}
}
Return R;
}




///   <Summary>  
/// Conversion of Chinese characters into the first letter of Pinyin
///   </Summary>  
///   <Param name = "str"> Chinese characters </Param>  
///   <Returns> Initial letter </Returns>  
Public   Static   String Getfirstpinyin ( String Str)
{
String R =   String . Empty;
Foreach ( Char OBJ In Str)
{
Try
{
Chinesechar =   New Chinesechar (OBJ );
String T = Chinesechar. pinyins [ 0 ]. Tostring ();
R + = T. substring ( 0 , 1 );
}
Catch
{
R + = OBJ. tostring ();
}
}
Return R;
}
}
}


 



Call method: (reference first)



Getpinyin ("Wind shadows"); // obtain the full spelling
Getfirstpinyin ("wind shadow"); // get the first letter



 



Is it very simple? With this class library, it is much easier! By the way, I would like to add some simplified and simplified conversion methods, which may be used in some cases:



Pilot Import



UsingMicrosoft. International. converters. traditionalchinesetosimplifiedconverter;


///   <Summary>  
/// Convert simplified to traditional
///   </Summary>  
///   <Param name = "str"> Simplified Chinese Characters </Param>  
///   <Returns> Traditional Chinese Characters </Returns>  
Public   Static   String Gettraditional ( String Str)
{
String R =   String . Empty;
R = Chineseconverter. Convert (STR, chineseconversiondirection. simplifiedtotraditional );
Return R;
}
///   <Summary>  
/// Convert traditional to simplified
///   </Summary>  
///   <Param name = "str"> Traditional Chinese Characters </Param>  
///   <Returns> Simplified Chinese Characters </Returns>  
Public   Static   String GetSimplified( String Str)
{
String R =   String . Empty;
R = Chineseconverter. Convert (STR, chineseconversiondirection. traditionaltosimplified );
Return R;
}


Function overview of this class library



Microsoft Visual Studio International pack 1.0 provides the following features:


  • East Asia numeric formatting library-supports formatting lowercase numeric strings into uppercase numeric strings in simplified Chinese, traditional Chinese, Japanese, and Korean.
  • Japanese Kana conversion library-supports converting Japanese Kana to another Japanese character.
  • Japanese text alignment library-supports a Japanese-specific alignment format.
  • The Japanese Yomi auto-completion library-Class Library supports the input of the daily input method and an example of a text box control.
  • Korean auto complete Textbox Control-supports smart sensing of Korean input methods and text box controls automatically completed by input.
  • Simplified Chinese pin-yin conversion library-supports obtaining common attributes of simplified Chinese characters, such as pinyin, polyphonic words, Homophone Words, and strokes.
  • Traditional Chinese to simplified Chinese conversion library and add-in tool-supports conversion between simplified and Traditional Chinese. This component also contains a plug-in (add-in) in the integrated development environment of Visual Studio that supports conversion between simplified and Traditional Chinese resource files.


     



    Visual Studio International Feature Pack 2.0 is an extension of version 1.0, including a set of controls and class libraries:


    • The yomigana framework contains class libraries and controls.


      • Class Library: The yomigana class library allows you to add yomigana to the string type, and also supports annotation for the general type, any object that implements the ienumerable interface can be annotated by string type and generic instance. To simplify the comparison of complex annotation strings, a comparison type that supports various Japanese comparison options is designed.


        • Some generic classes use generics to enable injection for an enumerable type.
        • For special purposes, you can use the generic above to enable certain types of sound injection for a string.
        • For special purposes, the stringannotation class uses the above generic to enable a string to be voiced, including the parsing and formatting functions.
        • A comparator class that compares strings.
        • A Data Structure that implements ienumerable <string>, divides a string into enumerated string segments, and outputs it using ienumerator <string>.
      • Controls:
        • The enhanced ajax/WPF/winform text box (textbox) control is used to capture pronunciation based on user input.
        • An enhanced ASP. NET label control that uses Ruby labels.
    • The Chinese Text alignment class library and textbox controls contain the winform and WPF textbox controls that support simplified Chinese Text alignment, and a class library that helps developers easily align and display strings according to Chinese text.
    • Chinese auto complete class library and textbox controls include textbox controls that support simplified Chinese and Traditional Chinese Input Methods and automatically complete winform and WPF, and a class library that allows developers to easily add sensor input methods to standard controls and automatically complete functions.
    • Korean auto complete class library and ComboBox controls include the winform and WPF ComboBox controls that support awareness of Korean input methods and are automatically completed, and a class library that allows developers to easily add sensor input methods to standard controls and automatically complete functions.
    • Numeric formatting class library contains classes that support formatting numbers in five languages into texts. Version 2.0 supports formatting Arabic numerals into Arabic texts.


    It can be seen that this class library is being developed internationallyProgramIs very practical.


  • 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.