I am getting a packet of data from an instrument. The strings in the
data packet are null terminted. What is the best way to extract a
string from the data packet?
I am working in .Net 20.
Presently the code reads byte by byte through the packet adding the
value into a List<byte>. The a new byte[] is created based on the
count of the List<byte>. The code iterates though the List<byte> to
populate the byte[]. Finally the byte[] is passed to an instance of
Encoding to get the string.
Is there a better way which does not require looping thourgh the string
twice?
data packet are null terminted. What is the best way to extract a
string from the data packet?
I am working in .Net 20.
Presently the code reads byte by byte through the packet adding the
value into a List<byte>. The a new byte[] is created based on the
count of the List<byte>. The code iterates though the List<byte> to
populate the byte[]. Finally the byte[] is passed to an instance of
Encoding to get the string.
Is there a better way which does not require looping thourgh the string
twice?
Comment