Convert a single Chinese character into Pinyin, you can also get the first letter of the Chinese character

  /// <summary>
  /// Convert a single Chinese character into Pinyin
  /// </ summary>
  /// <param name = "SingleChs"> Single Chinese character </ param>
  /// <returns> Pinyin </ returns>
      public static string SingleChs2Spell (string SingleChs)
  {
   byte [] array;
   int iAsc;
   string strRtn = string.Empty;

   array = Encoding.Default.GetBytes(SingleChs);

   try
   {
    iAsc = (short) (array[0]) * 256 + (short) (array[1]) - 65536;
   }
   catch
   {
    iAsc = 1;
   }

   if (iAsc > 0 && iAsc < 160)
    return SingleChs;

   for (int i = (pyvalue.Length - 1); i >= 0; i--)
   {
    if (pyvalue[i] <= iAsc)
    {
     strRtn = pystr[i];
     break;
    }
   }

 

-------------------------------------------------- ------------------------------- The above part is to get the complete spelling of Chinese characters ----------- --------------------------

   // Turn the first letter to uppercase
   if (strRtn.Length> 1)
   {
    strRtn = strRtn.Substring (0, 1) .ToUpper () + strRtn.Substring (1);
   }

-------------------------------------------------- ---------- The above small piece of code is used to get the first letter ---------------------------- ---------------

   return strRtn;
  }

Published 28 original articles · Like 15 · Visits 110,000+

Guess you like

Origin blog.csdn.net/z3h0a5n8g8x9i9a2o3/article/details/9001501