我编写了读取网络流并将数据存储到字节数组中的代码,然后将该字节数组转换为字符串数组。
我想从字符串数组或直接从字节数组中删除不可打印的 ASCII 字符(代码 28 即文件分隔符)。
我怎样才能达到同样的效果?
我尝试了以下代码:
saBytesReceived = saBytesReceived.Select(s => s.Replace(@"[^U+001C]", "")).ToArray();
代码 :-
if (serverSocket.Connected)
{
bBytesToRead = serverSocket.Available;
if (bBytesToRead > 0)
{
try
{
bDataReceived = new byte[bBytesToRead];
networkStream.Read(bDataReceived, 0, bBytesToRead);
try
{
if (System.Text.ASCIIEncoding.ASCII.GetString(bDataReceived).Trim() != "")
{
uncompletedMessage.IdleCount = 0;
saBytesReceived = System.Text.ASCIIEncoding.ASCII.GetString(bDataReceived).Split(new string[] { "\n" }, StringSplitOptions.None);
saBytesReceived = saBytesReceived.Select(s => s.Replace(@"[^U+001C]", "")).ToArray();
}
}
}
}
}