STRCOMP for array?
T Chap
Posts: 4,223
Is there a shortcut to search an array for something? Say that a device sends the Prop some data, 512 bytes for example. The Prop stores the data in an array. This is how I currently do it:
In this simple example, it is easy to see if the serial rx contains a word and value, then do something with the result. This works fine but seems bulky. This example expects a 1 to do anything, other examples could have unknown numbers that follow the =, which would then would need to be converted to an integer and sent to the next method for use.
' receive the data here from some source that contains TEST1=1, could be from a web page, GET or POST PUB ParseInput | i ser.str(1, string("TEST1")) 'display ser.tx(1, CR) i := 0 repeat 512 if response[i] == "T" if response[i+1] == "E" if response[i+2] == "S" if response[i+3] == "T" if response[i+4] == "1" if response[i+5] == "=" if response[i+6] == "1" DoSomething Return i++
In this simple example, it is easy to see if the serial rx contains a word and value, then do something with the result. This works fine but seems bulky. This example expects a 1 to do anything, other examples could have unknown numbers that follow the =, which would then would need to be converted to an integer and sent to the next method for use.
Comments
This is part of the attached object which contains methods written or converted by me and many others.
It think the red code can only be met in case that you pass an empty string (with strlen = 0 ). So for optimization I'd remove it from the loop: < smart a**-mode off >
;o)
Of course this is untested, as I have to work ;o)