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、