Parsing incoming string of varying length help
zooeyl
Posts: 13
Being a bit of a novice I have a question about incoming strings and extracting the information. I've used LEFT_STRING, RIGHT_STRING, MID_STRING before for various things, but I'm not sure how to go about retrieving the information for the following:
I have a large video matrix (512 in x 128 out) that has custom software inside that sends a serial string anytime a change has been made. I then take that string and extract the change and send a different string to an audio matrix. The string does have a start and end bit, but can have multiple changes. I need to be able to extract each change and send a string to the audio matrix. An example of a single change in the video matrix is as follows: 0x02M0001C00002L000000100x03 (the 0x02 is the start and the 0x03 is the end. In this case in need to extract M0001 and C00002 and can ignore the rest. I need to assign the M and C numbers to different variables. The matrix can also send multiple changes within the 0x02 - 0x03. It just repeats the M____C____L____ format within the start and stop bits. So it could look like: 0x02M0001C00003L00000100M0003C00010L000003000x03
I take the M number and the C number and translate that into a string that the audio matrix can use and send it. Any suggestions on extracting the information I need?
Thanks
I have a large video matrix (512 in x 128 out) that has custom software inside that sends a serial string anytime a change has been made. I then take that string and extract the change and send a different string to an audio matrix. The string does have a start and end bit, but can have multiple changes. I need to be able to extract each change and send a string to the audio matrix. An example of a single change in the video matrix is as follows: 0x02M0001C00002L000000100x03 (the 0x02 is the start and the 0x03 is the end. In this case in need to extract M0001 and C00002 and can ignore the rest. I need to assign the M and C numbers to different variables. The matrix can also send multiple changes within the 0x02 - 0x03. It just repeats the M____C____L____ format within the start and stop bits. So it could look like: 0x02M0001C00003L00000100M0003C00010L000003000x03
I take the M number and the C number and translate that into a string that the audio matrix can use and send it. Any suggestions on extracting the information I need?
Thanks
0
Comments
This is another method, it will get all the M C L values and in the string... This method does not care how long the each M C L are. If the values of M C L exceed an integer, make all the integers LONGs.
something like . . .
Positive, ATOI will parse until it gets to the first non-numeric ascii char. No need to do the left strings... Try it, it works really cool!!!!!
- Chip
OTOH, if he doesn't want an integer value, and he actually wants the characters, he'd need to do the left strings.
I'm gonna have to remember ATOI works that way though, thats a new one on me.
J
This will get you the characters you like regardless of how many there are between the 'M' and the 'C'.
If you don't care about leading zeros, AMXJeff's solution rocks - works great for getting verbose device feedback values up onto an indirect text button in a more human-friendly way.
- Chip
$02M0001C00002L00000010M0002C00005L00000222$03
With multiple instances of M, C, & L how would you extract each instance individually?