Convert text to PinYin

Source: Internet
Author: User

# Region -- get the first letter of a contact's name (method 1)
Public static string getpystring (string Str)
{
String _ temp = NULL;
For (INT I = 0; I <Str. length; I ++)
_ Temp = _ temp + getoneindex (Str. substring (I, 1 ));
Return _ temp. toupper ();
}

Public static string getpychar (string C)
{
Byte [] array = new byte [2];
Array = system. Text. encoding. Default. getbytes (C );
Int I = (short) (array [0]-'\ 0') * 256 + (short) (array [1]-' \ 0 '));

If (I <0xb0a1) Return "*";
If (I <0xb0c5) Return "";
If (I <0xb2c1) Return "B ";
If (I <0xb4ee) Return "C ";
If (I <0xb6ea) Return "D ";
If (I <0xb7a2) Return "E ";
If (I <0xb8c1) Return "F ";
If (I <0xb9fe) Return "G ";
If (I <0xbbf7) Return "H ";
If (I <0xbfa6) Return "G ";
If (I <0xc0ac) Return "K ";
If (I <0xc2e8) Return "L ";
If (I <0xc4c3) Return "M ";
If (I <0xc5b6) Return "N ";
If (I <0xc5be) Return "O ";
If (I <0xc6da) Return "p ";
If (I <0xc8bb) Return "Q ";
If (I <0xc8f6) Return "R ";
If (I <0 xcbfa) Return "S ";
If (I <0 xcdda) Return "T ";
If (I <0xcef4) Return "W ";
If (I <0xd1b9) Return "X ";
If (I <0xd4d1) Return "Y ";
If (I <0xd7fa) Return "Z ";
Return "*";
}
# Endregion

# Region -- get the first letter of a contact's name (method 2)
/// <Summary>
/// Obtain the first letter of the contact name
/// </Summary>
/// <Param name = "name"> name </param>
/// <Returns> initial name </returns>
Public static string get_name_frist (string name)
{
String _ temp = NULL;
For (INT I = 0; I <name. length; I ++)
_ Temp = _ temp + getoneindex (name. substring (I, 1 ));
Return _ temp. toupper ();
}
// Obtain the first letter of a single character
Private Static string getoneindex (string oneindextxt)
{
If (convert. tochar (oneindextxt)> = 0 & convert. tochar (oneindextxt) <256)
Return oneindextxt;
Else
{
Encoding gb2312 = encoding. getencoding ("gb2312 ");
Byte [] unicodebytes = encoding. Unicode. getbytes (oneindextxt );
Byte [] gb2312bytes = encoding. Convert (encoding. Unicode, gb2312, unicodebytes );
Return getx (convert. toint32 (
String. Format ("{0: D2}", convert. toint16 (gb2312bytes [0])-160)
+ String. Format ("{0: D2}", convert. toint16 (gb2312bytes [1])-160)
));
}
}

// Obtain the first letter Based on the location
Private Static string getx (INT gbcode)
{
If (gbcode> = 1601 & gbcode <1637) Return "";
If (gbcode> = 1637 & gbcode <1833) Return "B ";
If (gbcode> = 1833 & gbcode <2078) Return "C ";
If (gbcode> = 2078 & gbcode <2274) Return "D ";
If (gbcode> = 2274 & gbcode <2302) Return "E ";
If (gbcode> = 2302 & gbcode <2433) Return "F ";
If (gbcode> = 2433 & gbcode <2594) Return "G ";
If (gbcode> = 2594 & gbcode <2787) Return "H ";
If (gbcode> = 2787 & gbcode <3106) Return "J ";
If (gbcode> = 3106 & gbcode <3212) Return "K ";
If (gbcode> = 3212 & gbcode <3472) Return "L ";
If (gbcode> = 3472 & gbcode <3635) Return "M ";
If (gbcode> = 3635 & gbcode <3722) Return "N ";
If (gbcode> = 3722 & gbcode <3730) Return "O ";
If (gbcode> = 3730 & gbcode <3858) Return "p ";
If (gbcode> = 3858 & gbcode <4027) Return "Q ";
If (gbcode> = 4027 & gbcode <4086) Return "R ";
If (gbcode> = 4086 & gbcode <4390) Return "S ";
If (gbcode> = 4390 & gbcode <4558) Return "T ";
If (gbcode> = 4558 & gbcode <4684) Return "W ";
If (gbcode> = 4684 & gbcode <4925) Return "X ";
If (gbcode> = 4925 & gbcode <5249) Return "Y ";
If (gbcode> = 5249 & gbcode <= 5589) Return "Z ";
If (gbcode> = 5601 & gbcode <= 8794)
{
String codedata = "success"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Alarm"
+ "Success ";
String _ gbcode = gbcode. tostring ();
Int Pos = (convert. toint16 (_ gbcode. substring (0, 2)-56) * 94 + convert. toint16 (_ gbcode. substring (_ gbcode. length-2, 2 ));
Return codedata. substring (POS-1, 1 );
}
Return "";
}

Convert text to PinYin

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.