获取转UTF8的字符串

Posted Jack毛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取转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

 

以上是关于获取转UTF8的字符串的主要内容,如果未能解决你的问题,请参考以下文章