我已經編寫了讀取網絡流並將數據存儲到字節數組中的代碼,然後將該字節數組轉換爲字符串數組。刪除ASCII字符28從字符串數組
我想從字符串數組或直接從字節數組中刪除不可打印的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();
}
}
}
}
}