Obtain the first letter (uppercase) of the character string based on the Chinese character. It contains multiple audio characters.

Source: Internet
Author: User

/// <Summary>
/// Obtain the first letter (uppercase) of the character string based on the Chinese character, including the polyphonic words
/// </Summary>
/// <Param name = "chineseStr"> </param>
/// <Returns> </returns>
Public static string GetFirstSpellByChinese (string chineseStr)
{
Int I, j, k, m;
String tmpStr;
String returnStr = ""; // string that returns the final result
String [] tmpArr;
For (I = 0; I <chineseStr. Length; I ++)
{// Process the Chinese character string and cycle the first letter of each Chinese Character
TmpStr = GetShellByChinese (char) chineseStr [I]); // obtain the first letter of the Chinese character I, which may be one or more
If (tmpStr. Length> 0)
{// Only the first letter of Chinese Characters in Chinese pinyin can be operated.
If (returnStr! = "")
{// Not the first Chinese Character
Regex regex = new Regex (",");
TmpArr = regex. Split (returnStr );
ReturnStr = "";
For (k = 0; k <tmpArr. Length; k ++)
{
For (j = 0; j <tmpStr. Length; j ++) // concatenates each of the returned initials.
{
String charcode = tmpStr [j]. ToString (); // retrieve the j-character alphabet.
ReturnStr + = tmpArr [k] + charcode + ",";
}
}
If (returnStr! = "")
ReturnStr = returnStr. Substring (0, returnStr. Length-1 );
}
Else
{// Construct the first Chinese Character return result
For (m = 0; m <tmpStr. Length-1; m ++)
ReturnStr + = tmpStr [m] + ",";
ReturnStr + = tmpStr [tmpStr. Length-1];
}
}
}
Return returnStr; // return the processing result string, which is used to separate each pinyin combination.
}
/// <Summary>
/// Obtain the first character string of a single Chinese Character
/// </Summary>
/// <Param name = "chineseCh"> </param>
/// <Returns> </returns>
Private static string GetShellByChinese (char chineseCh)
{
// The Chinese Character and Pinyin initials list. The list contains 20902 Chinese characters. The Unicode encoding range of the included characters is 19968 to 40869.
String strChineseFirstPY =
// 375 polyphonic words are included here
String MultiPinyin =
String resStr = "";
Int I, j, uni;
Uni = (UInt16) chineseCh;
If (uni> 40869 | uni <19968)
Return resStr;
// Returns the encoding value of the character in the Unicode Character Set.
I = MultiPinyin. IndexOf (uni. ToString ());
// Check whether it is a Polyphonic word. If it is not, find the corresponding initial character in the strChineseFirstPY string.
If (I <0)
// Obtain the first letter of a non-polyphonic Chinese Character
{
ResStr = strChineseFirstPY [uni-19968]. ToString ();
}
Else
{// Obtain the first letter of a Multi-tone Chinese Character
J = MultiPinyin. IndexOf (",", I );
ResStr = MultiPinyin. Substring (I + 6, j-I-6 );
}

Return resStr;
}

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.