Separate String

Have a good day All

I have a String format like this

String myString = "\0x77\1\2\2\3\0x88";

Please advice how can separate each string from above string


String a = 0x077

String b = 1

String c =

Like wise

I am using Arduino UNO
Thanks in advance

'' is a special character and should not be used like you do. Use another character, such as '|'. Use char arrays instead of Strings, then you can use function strtok :slight_smile:

Here is an example: C++ code - 29 lines - codepad

+1 guix suggestion, ‘’ is a special character used as escape char.

I posted a code to split an array using strtok_r, check this post

If you wanted to use String then below code will be helpful

String split(String data, char separator, int index)
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;

  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";

//How to call
String myString = "0x77|2|2|3|0x88";
String splited = split(myString, '|',0)
//returns 0x77

Thanks all