string转Unicode

1、来自网络

        public static byte[] setByte2(string str, int len)
        {
            byte[] b = Encoding.Default.GetBytes(str);

            byte[] unicodeBytes = Encoding.Convert(Encoding.Default, Encoding.Unicode, b);
            //MessageBox.Show(unicodeBytes.Length.ToString());
            byte[] s = new byte[len];
            for (int i = 0; i < unicodeBytes.Length; i++)
            {
                s[i] = unicodeBytes[i];
            }
            for (int i = unicodeBytes.Length; i < len; i++)
            {
                s[i] = 0;
            }
            return s;
        }

 

2、

 

posted @ 2016-05-31 16:41  csskill  阅读(189)  评论(0编辑  收藏  举报