private void sendBCode()
{
NetworkStream serverStream = clientSocket.GetStream();
outStream = Encoding.ASCII.GetBytes("0000|ORD|SUPP");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
/*No issues so far, I am sending a data stream in the code above. Now I need
to return data:*/
byte[] inStream = new byte[1500];
var count = serverStream.Read(inStream, 0, inStream.Length);
string returndata = Encoding.ASCII.GetString(inStream, 0, count);
/*The data I am returning looks like: "0000|ORD|SUPPS|MWH|GGR|MBS" , below I will
split this data and populate a listBox with the returned data.*/
string[] s = null;
s = returndata.Split('|');
listBox1.DataSource = s returndata.Split('|');
}
listBox被成功填充,但是,我希望拆分字符串的前三项不显示在列表框中,这意味着我想从中排除“0000”,“ORD”和“SUPPS”列表框。有人可以帮忙吗?
答案 0 :(得分:4)
使用:
.Split('|').Skip(3)
应该有用吗?
您可以随时删除分割后的内容
编辑:不知道你从哪里得到这个错误,但我只是尝试了这个并且它工作得很好:
string returndata = "0000|ORD|SUPPS|MWH|GGR|MBS";
string[] s = null;
s = returndata.Split('|');
listBox1.DataSource = s.Skip(3).ToArray();