1. 程式人生 > >C#字串轉UNICODE

C#字串轉UNICODE

 public static string StringToUnicode(string s)//字串轉UNICODE程式碼
        {

            char[] charbuffers = s.ToCharArray();

            byte[] buffer;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < charbuffers.Length; i++)

            {

                buffer 
= System.Text.Encoding.Unicode.GetBytes(charbuffers[i].ToString()); sb.Append(String.Format("\\u{0:X2}{1:X2}", buffer[1], buffer[0])); } return sb.ToString(); }