String st = "TV-R3-0x1109807F-TV-R1-0xFF9807F-TV-R9-0xF9807F-STB-R1-0xF807F-STB-R3-0xC0000C"; void setup() { String protocol; String rep; String form; Serial.begin(9600); char str[200]; st.toCharArray(str, 200); char* token = strtok(str, "-"); while (token != NULL) { // Serial.println(val); String keys = String(token); if (keys[0] == '0' && keys[1] == 'x') { receive(protocol, keys, rep); form += keys+"-"; // Serial.println("found"); } else if (keys[0] == 'R' && isDigit(keys[1])) { rep = keys; if(keys != "k1"){ form += keys+"-"; } } else { if(protocol != keys){ form += keys+"-"; } protocol = keys; } // Serial.println(token); // Serial.println(token); token = strtok(NULL, "-"); } int gf = form.length()-1; form.remove(form.length()-1, 1); Serial.println("Your input: "+st); Serial.println("Simplified form: "+form); } void loop() { } void receive(String k, String val, String repeat) { char valch[50]; val.toCharArray(valch, 50); repeat.remove(0, 1); long unsigned int b = strtoul(valch, NULL, 16);// For converting HEX to decimal Serial.println(k + " " + val + " " + b + " Rep=" + repeat); }