I'm writing in Keil C51 using Zigbee.
Serial_txString0("AT+UCAST:000D6F0000BB769D=StartGreen");
tx_port0(0x0D);
For example, I will receive "AT+UCAST:000D6f0000BB769D=StartGreen", I want to filter that to only get "StartGreen".
How about:
char *eq = strrchr(str, '=');
if (eq)
printf("%s\n", eq + 1);
=, increments one step (to the S) and then prints it.From one example, I can't really tell based on what do you want to filter. Does something like this suffice (extracting the part of string after =) ?
char* filter(char* input) {
int i = 0;
while (input[i] && input[i] != '=') i++;
return &input[i + 1];
}
Note that this does not copy the string, only refers to the right part of it. If you want to actually extract the filtered part...
void filter(char* input, char* output) {
int i = 0;
while (input[i] && input[i] != '=') i++;
strcpy(output, &input[i + 1]);
}
...using strcpy in <string.h>.
while (input[i] != '=') i++; This assumes that the string will contain a '=' character. If it doesn't, it will iterate beyond the null termination and check the whole computer's memory in search of a binary goo that is equivalent to the ASCII code '='. Use strchr() instead, or write code that checks for null termination.= to be there. But ok, I changed it accordingly.= is not present in the string, this will return an empty string, what is probably semantically correct.