I have written code which reads network stream and stores data into byte array, then convert that byte array to string array.
I want to remove non printable ASCII character (Code 28 i.e. File Separator) from string array or directly from byte array.
How can I achieve the same ?
I tried following code:
saBytesReceived = saBytesReceived.Select(s => s.Replace(@"[^U+001C]", "")).ToArray();
Code :-
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();
}
}
}
}
}
Not sure about the byte array but from the string you can use string.Replace. If its a single string:
For array: