Small Parsing Problem
SCOTTYP
Posts: 32
I was just messing around with some strings yesterday and could not get this working.....Could anyone take a quick look and let me know what Im doing wrong?? If you have some advice about my form LMK.
Nothing makes it into the msgQue...It makes it into vBuffer. Im sure it something retarded on my part...again.
LOCAL_VAR vBuffer[70]
LOCAL_VAR msgQue[70]
vBuffer = "vBuffer,DATA.TEXT"
msgQue=left_string(vBuffer,7)
while(find_string(vBuffer,"'P'",1))
{
msgQue=remove_string(vBuffer,1,7)
switch(msgQue)
{
case 'PowerOn':
{
PowerOn();
}
}
}
}
Nothing makes it into the msgQue...It makes it into vBuffer. Im sure it something retarded on my part...again.
LOCAL_VAR vBuffer[70]
LOCAL_VAR msgQue[70]
vBuffer = "vBuffer,DATA.TEXT"
msgQue=left_string(vBuffer,7)
while(find_string(vBuffer,"'P'",1))
{
msgQue=remove_string(vBuffer,1,7)
switch(msgQue)
{
case 'PowerOn':
{
PowerOn();
}
}
}
}
0
Comments
Try this
Jeff
The only problem with this is if the data comes in broken. If this is in fact in the command section tho, the AMX processor should not break commands.
As for my original reply, you could insert this code before the get_buffer_string() to strip out everything before the 'P':
get_buffer_string(vBuffer,(find_string(vBuffer,"'P'",1)-1));
The only problem that might come up is if the 'P' is the first character. I'm not sure how a get_buffer_string with a 0 value will work.
Jeff
I'd try it. GET_BUFFER_STRING(any_string,0) should have absolutely no effect, based on the description of what GET_BUFFER_STRING does. If it does something unexpected, like gobble up your whole string and result it as the function's result, well, we'll learn something
Command:
{
LOCAL_VAR vBuffer[70]
STACK_VAR msgQue[70]
STACK_VAR x
vBuffer = DATA.TEXT
msgQue=left_string(vBuffer,7)
while(find_string(msgQue,"'P'",1))
{
switch(msgQue)
{
case 'PowerOn':
{
PowerOn(); //power on function
}
}
}
}
If you are really worried about the while loop getting stuck, you could change it to be this:
Try that code and see if it works.
Jeff
here is how the select..active would look:
Jeff
I would just do this:
The reason why. It highly unlikely that you are going to overrun DATA.TEXT especially if you know what you are sending to it. Every subsequent send_command will overwrite DATA.TEXT and not append the information so there is no need to parse the buffer because it's not buffering. Again, I'm not too sure if this is what you are trying to do.