赞
踩
版权声明:本文博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
根据https://blog.csdn.net/RazilFelix/article/details/52314542 修改 ,在原方法上修改后才能用
public short[] stringToShort(String inString, out short[] outShort) { if (inString.Length % 2 == 1) { inString += " "; } char[] bufChar = inString.ToCharArray(); byte[] oufByte = Encoding.Default.GetBytes(bufChar); // new byte[bufChar.Length]; byte[] bufByte = new byte[2]; outShort = new short[bufChar.Length / 2]; for (int i = 0, j = 0; i < bufChar.Length; i += 2, j++) { bufByte[0] = oufByte[i]; bufByte[1] = oufByte[i + 1]; outShort[j] = BitConverter.ToInt16(bufByte, 0); } return outShort; } private void button1_Click(object sender, EventArgs e) { short[] arr2 = new short[16]; String inString = "12ABCDEFGHIJKLMNOPQRSTUVWXYZPP34"; stringToShort(inString, out arr2); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。