c++ - comparing strings when 1 string contains part of the other string -
i using following code compare packetbuffer string,
char packetbuffer[udp_tx_packet_max_size]; !strcmp(packetbuffer, "turn on light")
however how use compare string should packetbuffer = testing1234 , string compared equal "testing", out last 4 digits?
the function looking strstr:
if (strstr(packetbuffer, "testing") != null) { // packetbuffer contains "testing" // something... }
note: if need test substring @ start of string can this:
if (strstr(packetbuffer, "testing") == packetbuffer) { // packetbuffer starts "testing" // something... }
Comments
Post a Comment