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