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

Source: Internet
Author: User

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

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 traditional 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: C: \ Program Files \ Microsoft Visual Studio International Pack \ Simplified Chinese Pin-Yin Conversion Library (pinyin) and C: \ Program Files \ Microsoft Visual Studio International Pack \ Traditional Chinese to Simplified Chinese Conversion Library and Add-In Tool (simple Conversion) dll can be used.

After completing the above work, the usage is very simple. Let's look at the code below:

 

Using Microsoft. International. Converters. PinYinConverter; // import pinyin

Namespace WebApplication2
{
Public class Class1
{
/// <Summary>
/// Convert 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 chineseChar = new ChineseChar (obj );
String t = chineseChar. Pinyins [0]. ToString ();
R + = t. Substring (0, t. Length-1 );
}
Catch
{
R + = obj. ToString ();
}
}
Return r;
}

/// <Summary>
/// Convert Chinese characters to the first letter of the pinyin alphabet
/// </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 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

Using Microsoft. International. Converters. TraditionalChineseToSimplifiedConverter;

 

/// <Summary>
/// Convert simplified to traditional
/// </Summary>
/// <Param name = "str"> simplified Chinese character </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 Chinese to simplified Chinese
/// </Summary>
/// <Param name = "str"> traditional Chinese character </param>
/// <Returns> simplified Chinese character </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 very practical when developing international programs.

 


C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

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.