get uppercase initials

    Trial scenarios: contact grouping, text spelling, etc.

    When executing the Encoding.GETEncoding("GBK") method, the Android version will display the following error message (IOS generally does not appear):


  Solution: Right-click the Android project, select the "Properties" button, select " CJK " in the " Android Options" column, save it, clean the project and run it again.



/// <summary>
        /// Returns the first letter of the given string
        /// </summary>
        /// <param name="IndexTxt"></param>
        /// <returns></returns>
        public static string GetStringSpell(String IndexTxt)
        {
            String _Temp = "-";
            for (int i = 0; i < IndexTxt.Length; i++)
            {
                string _Str = GetOneIndex(IndexTxt.Substring(i, 1));

                Regex regEnglish = new Regex("^[0-9a-zA-Z]");
                if (regEnglish.IsMatch(_Str))
                {
                    _Temp = _Str;
                    break;
                }

            }

            return _Temp.ToUpper();
        }

        /// <summary>
        /// Get the first letter of a single character
        /// </summary>
        /// <param name="OneIndexTxt"></param>
        /// <returns></returns>
        public static string GetOneIndex(String OneIndexTxt)
        {
            try
            {
                if (Convert.ToChar(OneIndexTxt) >= 0 && Convert.ToChar(OneIndexTxt) < 256)
                {
                    return OneIndexTxt;
                }

                else
                {
                    Encoding gbk = Encoding.GetEncoding("GBK");
                    byte[] unicodeBytes = Encoding.Unicode.GetBytes(OneIndexTxt);
                    byte[] gbkBytes = Encoding.Convert(Encoding.Unicode, gbk, unicodeBytes);
                    return GetX(Convert.ToInt32(String.Format("{0:D2}", Convert.ToInt16(gbkBytes[0]) - 160) + String.Format("{0:D2}", Convert.ToInt16(gbkBytes[1]) - 160)));
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return "";

        }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325594402&siteId=291194637