ASP. NET Chinese generation English

Source: Internet
Author: User

In OA project development, the user's login name is the pinyin name automatically generated after the Administrator enters the Chinese character name in the background. For example, if you enter Zhang San, the login name automatically generates zhangsan.

How can this be achieved? I checked the relevant information today, and it turns out to be as follows:

Microsoft provides a Microsoft Visual Studio International pack class library software package, vsintlpack1.zip, (now it seems there is vsipsetup. MSI, I did not try)

There is a Class Library: Simplified Chinese pin-yin conversion library. common attributes of simplified Chinese characters can be obtained.

Specific operations:

1、vsintlpack1.zip:

Http://www.microsoft.com/downloads/details.aspx? Familyid = 44cac7f0-633b-477d-aed2-99aee642fc10 & displaylang = ZH-CN

2. After downloading vsintlpack1.zip, decompress chspinyinconv. MSI to install it. For example, install it in c: \ Program Files \ Microsoft Visual Studio International pack \ Simplified Chinese pin-yin conversion library. You can see the following files.

3. Add a reference to the project and add the reference chncharinfo. dll under the installation directory of step 2.

After successful reference

 

4. the test method is as follows:

 

Code

  private string ConvertToPinYin(string str)
{
string PYstr = "";
foreach (char item in str.ToCharArray())
{
if (Microsoft.International.Converters.PinYinConverter.ChineseChar.IsValidChar(item))
{
Microsoft.International.Converters.PinYinConverter.ChineseChar cc = new Microsoft.International.Converters.PinYinConverter.ChineseChar(item);

//PYstr += string.Join("", cc.Pinyins.ToArray());
PYstr += cc.Pinyins[0].Substring(0, cc.Pinyins[0].Length - 1);
}
else
{
PYstr += item.ToString();
}
}
return PYstr;

}

 

5. I tested it briefly. It is good (input the Chinese character "Zhang San" in textbox1 to generate the pinyin "zhangsan ")

 

  protected void Button1_Click(object sender, EventArgs e)
{
string pinying = ConvertToPinYin(this.Textbox1.Text.Trim());
Response.Write(pinying);
}

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.