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.
Symbol in C Language <Yes
Left shift operator (<)
Removes all the binary bits of an operation object from the left and adds 0 to the right ).
For example, a = a <2 shifts the binary bits of a two places to the left and complements 0 to the right,
Move 1 to the left and then a = a * 2;
If the left shift does not include 1 in the Discard high position, then shifts one bit left, which is equivalent to multiplying the number by 2.
Shift right operator (>)
Shifts all the binary bits of a number to several places to the right, and adds 0 to the left of the positive number, 1 to the left of the negative number, and discards the right of the negative number.
The operand shifts one digit to the right, which is equivalent to dividing the number by 2.
For example, a = a> 2 shifts the binary bit of a two places to the right,
0 or 1 to see whether the number is positive or negative.
Symbol in C Language <Yes
Left shift operator (<)
Removes all the binary bits of an operation object from the left and adds 0 to the right ).
For example, a = a <2 shifts the binary bits of a two places to the left and complements 0 to the right,
Move 1 to the left and then a = a * 2;
If the left shift does not include 1 in the Discard high position, then shifts one bit left, which is equivalent to multiplying the number by 2.
Shift right operator (>)
Shifts all the binary bits of a number to several places to the right, and adds 0 to the left of the positive number, 1 to the left of the negative number, and discards the right of the negative number.
The operand shifts one digit to the right, which is equivalent to dividing the number by 2.
For example, a = a> 2 shifts the binary bit of a two places to the right,
0 or 1 to see whether the number is positive or negative.