How to read data on networkstream upto specific character?
I have written a code to receive data from networkstream and if data contains first character "$" then i identify this data as barcodes data, but sometimes when data is large like 7000byte at that time data coming in packets of different sizes but some bytes not detected as they miss "$" symbol in starting . so i want to read data till specified byte like "*". The data sent by client starts with "$" and ends with "*". here is my program .plese help , thanks
List<byte> list = new List<byte>();
networkStream = clientSocket.GetStream();
for (int p = 0; p >= 0; p++)
{
b = new byte[5000];
int k = networkStream.Read(b, 0, b.Length);
for (int i = 0; i < k; i++)
{
Convert.ToChar(b[i]);
}
var j = b.Length - 1;
while (b[j] == 0)
{
--j;
}
var temp = new byte[j + 1];
Array.Copy(b, temp, j + 1);
string res = System.Text.Encoding.ASCII.GetString(temp);
switch (res.Substring(0, 1))
{
case "$":
if (res.StartsWith("$")) //barcode string
{
//barcode//
list.Add(res);
if(res.Contains("*"))
{
string collection = string.Join("", list);
}
}
else{}
break;
}
}
}