How do I parse data received in a memorystream?

Posted by Kerberos42 on Stack Overflow See other posts from Stack Overflow or by Kerberos42
Published on 2013-11-06T03:13:29Z Indexed on 2013/11/06 3:54 UTC
Read the original article Hit count: 153

Filed under:
|
|

I'm new to using sockets. I have a very basic client that sends a request, and waits for a response. The response is one stream, but has two parts. The first part is prefixed with ANS and is a set of key/value pairs in this form: KEY:Value with each pair on a separate line.

The second part of the response is prefixed by RCT and this is pre-formatted text that needs to be send directly to a printer.

So what would be the best way to extract both parts of the response, and in the first part, get each Key:Value pair. I might not even need them all, but I have to look at each one to see what the values are then decide what to do with it.

I'm currently writing the response out to a textbox just to understand what its doing, but now I need to actually do something with the data.

Here's a data sample, as it is received:

ANS Result: Data Received                                                                
RCPRES:Q[81]
TML:123
OPP:
MRR:000000999999
<several dozen more KEY:Value pairs>
RCTNov 05 2013  04:03 pm      Trans# 123456

           <pre-formatted text>

© Stack Overflow or respective owner

Related posts about c#

Related posts about sockets