Asp. NET Chinese pinyin-input Chinese characters to obtain the specific implementation of its pinyin _ practical skills

Source: Internet
Author: User
Tags pack microsoft website

Recently saw some friends to achieve the product name Pinyin input, found that his implementation of the way is manual input,-_-#, comrades, welfare came!

Microsoft Visual Studio International Pack, which is available in Chinese, Japanese, Korean, English, and other countries, provides a way to achieve mutual transfer, pinyin, word-count, Even get the number of strokes and so on.

Here is an example of the input of Chinese characters, to obtain their pinyin, to obtain pinyin and to obtain the first letter of pinyin implementation effects are as follows:

First, download the Microsoft Visual Studio International Pack Language Pack at Microsoft website, with the following download addresses:
Microsoft Visual Studio International Pack 1.0 SR1

Microsoft Visual Studio International Feature Pack 2.0

After the download is "Vsintlpack1.zip", "Vsintlpack2.msi", double-click the "Vsintlpack2.msi" installation, the path is arbitrary, but to remember, because a will be cited,
After the installation of "Vsintlpack2.msi", decompression "Vsintlpack1.zip", which contains seven language packs,
For example, Chinese pinyin "chspinyinconv.msi", simplified traditional "chtchsconv.msi" and so on.

Here we use "Chspinyinconv.msi", double-click the installation to succeed, open visual Studio, create a new WinForm project, form layout as shown above,

First: Add the Language Pack reference that you just installed:

"D:\Program Files (x86) \microsoft Visual Studio International pack\simplified Chinese pin-yin Conversion ChnCharInfo.dll "

The default is C disk, where I am installed in D, and then add a using reference:

Copy Code code as follows:

Using microsoft.international.converters.pinyinconverter;//import phonetic correlation

To create a method to get Ruby:
Copy Code code as follows:

<summary>
The conversion of Chinese characters into pinyin
</summary>
<param name= "str" > Chinese characters </param>
<returns> Total spelling </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;
}

To create a method to get the first letter of Chinese pinyin:
Copy Code code as follows:

<summary>
Convert Chinese characters into Pinyin first letter
</summary>
<param name= "str" > Chinese characters </param>
<returns> First 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;
}

Then invoke the above method in the "Pinyin" button's Click event:
Copy Code code as follows:

Pinyin for Chinese character conversion
private void Btn_one_click (object sender, EventArgs e)
{
String Source = This.txt_ChineseCharacter_One.Text.Trim (); Get the input source character
string result = Getpinyin (source); Call method, get Ruby
This.txt_Pinyin_One.Text = result;
}

Invoke the above method in the "Turn First letter" button click event:
Copy Code code as follows:

Turn first letter
private void Btn_two_click (object sender, EventArgs e)
{
String Source = This.txt_ChineseCharacter_One.Text.Trim (); Get the input source character
string result = Getfirstpinyin (source); Call method, get Ruby
This.txt_Pinyin_One.Text = result;
}

To this, has completed 80%, runs the program, you will discover, when clicks "The Pinyin" time, the result is this:

is not the kind of "Gu Ying" effect that I start to say, this is because I do the simple processing when acquiring pinyin:

Copy Code code as follows:

Pinyin for Chinese character conversion
private void Btn_one_click (object sender, EventArgs e)
{
String Source = This.txt_ChineseCharacter_One.Text.Trim (); Get the input source character

string result = String.   Empty; The results of the pinyin conversion
String temp = string. Empty; A temporary variable used by foreach below
foreach (char item in source)//traverse each source character
{
temp = Getpinyin (item.  ToString ()); Convert each character to pinyin
Processing: Get first letter uppercase, remaining letter lowercase
result = = (String.Format ("{0}{1}", temp.) Substring (0, 1). ToUpper (), temp. Substring (1). ToLower ()));
}

string result = Getpinyin (source); Call method, get Ruby
This.txt_Pinyin_One.Text = result;
}


OK, here, this function has been completed, and the rest of the language pack features, and this is similar, you can Baidu "Microsoft Visual Studio International Pack Use", the various languages of the mutual transfer and functional examples came out.

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.