Remove_String Issue
I'm baffled by this one. Using the Remove_String Command to parse some data that is returned from an XML sheet.
Here is the data returned:
and the code to parse it
the nWEB_TEMPERATURE returns the proper value, but the cWEB_ICON always returns the icon code plus </Icon> on the end and I cannot figure out why. (I know the cTRASHer is not needed, just added to see the data passed). The </Weather> data is left in the cWebBuffer.
Any idea why it's grabbing the </Icon> as well? I'm sure it's something rather simple.
Here is the data returned:
Alive Content-Type: text/plain <WeatherData><Temperature>45</Temperature><Icon>partlycloudy</Icon></WeatherData>
and the code to parse it
cTRASHer = REMOVE_STRING(cWebBuffer,'<Temperature>',1) nWEB_TEMPERATURE=atoi(REMOVE_STRING(cWebBuffer,'</Temperature>',1)) cTRASHer=REMOVE_STRING(cWebBuffer,'<Icon>',1) cWEB_ICON=REMOVE_STRING(cWebBuffer,'</Icon>',1)
the nWEB_TEMPERATURE returns the proper value, but the cWEB_ICON always returns the icon code plus </Icon> on the end and I cannot figure out why. (I know the cTRASHer is not needed, just added to see the data passed). The </Weather> data is left in the cWebBuffer.
Any idea why it's grabbing the </Icon> as well? I'm sure it's something rather simple.
0
Comments
Look Here
http://www.amxforums.com/showthread.php?8675-Processing-Received-Strings&p=60394#post60394
In this example, we know that '</icon>' is 7 characters, so the above statement would equate to "give me my buffer minus the last 7 characters."
DEFINE_FUNCTION CHAR[MAX_STR_SIZE] getBoundString(CHAR source[], CHAR startString[], CHAR endString[]) { INTEGER startIndex; INTEGER endIndex; CHAR response[MAX_STR_SIZE]; response = ""; // MAKE SURE THERE IS SOMETHING TO SEARCH IF (LENGTH_STRING(source) > 0) { startIndex = FIND_STRING(source, startString, 1); // MAKE SURE IT FOUND THE START STRING IF (startIndex > 0) { // ADJUST THE POSITION PAST THE START STRING startIndex = startIndex + LENGTH_STRING(startString); // FIND THE END STRING BASED ON THE START STRINGS POSITION endIndex = FIND_STRING(source, endString, startIndex); // IF THE ENDINDEX IS GREATER THAN THE START if (startIndex < endIndex) response = MID_STRING(source, startIndex, endIndex - startIndex); } } RETURN response; } DEFINE_START cTestString = '<?xml version="1.0"?><!--0000126--><SET_REG RT="C00" ID="0" L1PW="qsc"><REG_RATE S="50"/><REG O="0x001B0000" S="1"/></SET_REG>' send_string 0,"Length: ',getBoundString(cTestString,'<!--','-->')"; send_string 0,"Password: ',getBoundString(cTestString,'L1PW="','"')";I've never really given the efficiency aspect any consideration but moving a pointer and referencing pointers should definitely be more efficient and probably a more eloquent way to go about it. I'm more a bull in a china shop kinda guy compared to a ballet dancer who has grace, style and fluidity in motion.