Parsing a fixed-length string with a delimiter
<p>...where the delimiter might also be in the body.</p>

<p>I am working with an LCD display that has a protocol that uses the format below:</p>

<p>STX(1byte) + IDT(1byte) + Type(1byte) + CMD(3bytes) + [Value/Reply(1byte)] + ETX(1byte)</p>

<p>STX is 0x07, and ETX is 0x08. The IDT coming from the display could also be 0x08, which is causing me problems when trying to parse the response from the display. I didn't write the parsing routine, but am now tasked with making things work.</p>

<p>The original programmer's solution can be seen at <a href="https://gyazo.com/1fc74133e7109e5aa213f3f5878cc001" rel="nofollow">https://gyazo.com/1fc74133e7109e5aa213f3f5878cc001</a>. The problem is that when IDT is 0x08, the code just grabs the first 2 bytes in the response because 0x08 is the ETX as well as the IDT. I thought about using LastIndexOf, but the possibility exists that there would be more than one response from the display in the buffer. Any help is appreciated.</p>