SoFunction
Updated on 2025-03-06

C# Get the pinyin first letter of Chinese characters

C# Get the pinyin first letter of Chinese characters

Updated: June 26, 2015 15:10:21 Submission: hebedich
One is to collect all Chinese characters into a comparison table; the other is to determine the first letter of the pinyin according to the sorting of Chinese characters in the Unicode encoding table. When encountering polyphonic characters, the common ones shall be used as the basis (the first method can be changed by yourself. The method is to manually move the Chinese character to the corresponding pinyin first line queue. We will introduce the second one here

Getting the first letter of the Chinese character pinyin is a function that is often used in the process of doing projects. Today we will mainly discuss C# to get the first letter of the Chinese character pinyin

/// <summary>

/// Search the pinyin index string in the specified string list CnStr
/// </summary>

/// <param name="CnStr">Chinese character string</param>
/// <returns>The corresponding Chinese pinyin string</returns>
public static string GetSpellCode(string CnStr) {

string strTemp="";

int iLen=;

int i=0;

for (i=0;i&lt;=iLen-1;i++) {

 strTemp+=GetCharSpellCode((i,1));

}

return strTemp;

}

/// &lt;summary&gt;

/// Get the first letter of the pinyin of a Chinese character. If it is an English letter, it will directly return to the capital letter.
/// &lt;/summary&gt;

/// <param name="CnChar">Single Chinese Character</param>
/// <returns>Single capital letter</returns>
private static string GetCharSpellCode(string CnChar) {

long iCnChar;

byte[] ZW = (CnChar);

//If it is a letter, return directly
if (==1) {

 return ();

}

else {

 // get the array of byte from the single char

int i1 = (short)(ZW[0]);

int i2 = (short)(ZW[1]);

iCnChar = i1*256+i2;

}

// iCnChar match the constant

if ((iCnChar&gt;=45217) &amp;&amp; (iCnChar&lt;=45252)) {

 return "A";

}

else if ((iCnChar&gt;=45253) &amp;&amp; (iCnChar&lt;=45760)) {

return "B";

} else if ((iCnChar&gt;=45761) &amp;&amp; (iCnChar&lt;=46317)) {

return "C";

} else if ((iCnChar&gt;=46318) &amp;&amp; (iCnChar&lt;=46825)) {

return "D";

} else if ((iCnChar&gt;=46826) &amp;&amp; (iCnChar&lt;=47009)) {

return "E";

} else if ((iCnChar&gt;=47010) &amp;&amp; (iCnChar&lt;=47296)) {

return "F";

} else if ((iCnChar&gt;=47297) &amp;&amp; (iCnChar&lt;=47613)) {

return "G";

} else if ((iCnChar&gt;=47614) &amp;&amp; (iCnChar&lt;=48118)) {

return "H";

} else if ((iCnChar&gt;=48119) &amp;&amp; (iCnChar&lt;=49061)) {

return "J";

} else if ((iCnChar&gt;=49062) &amp;&amp; (iCnChar&lt;=49323)) {

return "K";

} else if ((iCnChar&gt;=49324) &amp;&amp; (iCnChar&lt;=49895)) {

return "L";

} else if ((iCnChar&gt;=49896) &amp;&amp; (iCnChar&lt;=50370)) {

return "M";

}else if ((iCnChar&gt;=50371) &amp;&amp; (iCnChar&lt;=50613)) {

return "N";

} else if ((iCnChar&gt;=50614) &amp;&amp; (iCnChar&lt;=50621)) {

return "O";

} else if ((iCnChar&gt;=50622) &amp;&amp; (iCnChar&lt;=50905)) {

return "P";

} else if ((iCnChar&gt;=50906) &amp;&amp; (iCnChar&lt;=51386)) {

return "Q";

} else if ((iCnChar&gt;=51387) &amp;&amp; (iCnChar&lt;=51445)) {

return "R";

} else if ((iCnChar&gt;=51446) &amp;&amp; (iCnChar&lt;=52217)) {

return "S";

} else if ((iCnChar&gt;=52218) &amp;&amp; (iCnChar&lt;=52697)) {

return "T";

} else if ((iCnChar&gt;=52698) &amp;&amp; (iCnChar&lt;=52979)) {

return "W";

} else if ((iCnChar&gt;=52980) &amp;&amp; (iCnChar&lt;=53640)) {

return "X";

} else if ((iCnChar&gt;=53689) &amp;&amp; (iCnChar&lt;=54480)) {

return "Y";

} else if ((iCnChar&gt;=54481) &amp;&amp; (iCnChar&lt;=55289)) {

return "Z";

} else

return ("?");

}

The above is the entire content of this article, I hope you like it.

  • C#
  • First letter

Related Articles

  • Introduction to Parallel Class of C# Parallel Library

    This article introduces the C# parallel library Parallel class, which is introduced in detail through sample code. It has certain reference value for everyone's study or work. Friends who need it can refer to it.
    2022-06-06
  • C# sliding verification code puzzle verification function implementation (SlideCaptcha)

    The verification code mechanisms on the website are currently varied, including simple digital verification, obfuscation verification with letters and text, and puzzle verification through sliders. The following article mainly introduces the implementation method of the C# sliding verification code puzzle verification function. Friends who need it can refer to it.
    2022-04-04
  • Unity3D realizes VR camera function based on gyroscope

    This article mainly introduces the functions of Unity3D based on gyroscopes to implement VR cameras. The sample code in the article is introduced in detail and has certain reference value. Interested friends can refer to it.
    2020-04-04
  • C# CM framework implements example code for multi-page management

    This article mainly introduces the implementation of multi-page management with one line of code in the C# CM framework. This article introduces you very detailed through the example code, which has certain reference value for your study or work. Friends who need it can refer to it.
    2022-03-03
  • C# Summary of various ways to obtain XML file content

    This article mainly introduces a summary of C#’s various ways to obtain XML file content, which is of good reference value and hopes to be helpful to everyone. If there are any mistakes or no complete considerations, I hope you will be very grateful for your advice
    2023-01-01
  • The latest tutorial on VS2019 packaging WPF installer (detailed explanation of pictures and text)

    This article mainly introduces the latest tutorial on VS2019 packaging WPF installation program. This article introduces you very detailed in pictures and texts, and has certain reference value. Friends who need it can refer to it.
    2019-11-11
  • Detailed explanation of Unity's plant recognition example

    This article mainly introduces how to connect to Baidu AI to achieve plant recognition through Unity, the interface returns the name of the plant, and supports obtaining encyclopedia information corresponding to the recognition results. If you are interested, please learn about it
    2022-01-01
  • Detailed explanation of the basic operations of C# winform ListView

    This article mainly introduces the basic operations of C# winform ListView. The example code is introduced in this article in detail and has certain reference value. Interested friends can refer to it.
    2022-01-01
  • Introduction to four ways of calling interfaces in C#

    This article introduces four ways to call the C# interface, and the article introduces it in detail through sample code. It has certain reference value for everyone's study or work. Friends who need it can refer to it.
    2022-06-06
  • The effect of screenshotting a specified web page C# version

    The effect of screenshotting the specified web page C# version...
    2007-08-08

Latest Comments