获取转UTF8的字符串

时间:2023-01-10 11:37:44
获取转UTF8的字符串获取转UTF8的字符串
        /// <summary>
        /// 获取转UTF8的字符串
        /// </summary>
        /// <param name="strWord"></param>
        /// <returns></returns>
        public static string GetUtf8String(string strWord)
        {
            string strRes = string.Empty;

            if (string.IsNullOrEmpty(strWord))
            {
                return strRes;
            }
            
            string s = BitConverter.ToString(System.Text.Encoding.UTF8.GetBytes(strWord));
            foreach (byte b in Encoding.UTF8.GetBytes(s))
            {
                strRes += '%' + b.ToString("X");
            }
            
            return strRes;
        }
View Code