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);
}