在填充列表框之前从拆分的字符串中移除元素

本文关键字:字符串 元素 拆分 列表 填充 | 更新日期: 2023-09-27 18:11:41

 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"answers"SUPPS"。有人能帮忙吗?

在填充列表框之前从拆分的字符串中移除元素

Using:

.Split('|').Skip(3)

应该工作吗?

你总是可以删除那些在分割后的

编辑:不知道你从哪里得到这个错误,但我只是试过这个,它工作得很好:

        string returndata = "0000|ORD|SUPPS|MWH|GGR|MBS";
        string[] s = null;
        s = returndata.Split('|');
        listBox1.DataSource = s.Skip(3).ToArray();