STRING TO SHORT[]方法
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);
}