Free help & advice Talk to us

  • Free shipping over A$55

    Within Australia

  • Free help & advice

    We reply within 24 hours

  • 30-day returns

    12-month warranty on faults

  • Ships next business day

    When the item is in stock

Split a String by Delimiters

Split a String by Delimiters

Lonely Binary |

Download vector.h from https://www.arduinolibraries.info/libraries/vector

 

Function

this function will take a string that is using commas to separate the values (AKA CSV format) and return a vector that is populated with the values.

the value of the following code is binary

splitStringToVector("lonely,binary")[1] 

 

std::vector<String> splitStringToVector(String msg){
  std::vector<String> subStrings;
  int j=0;
  for(int i =0; i < msg.length(); i++){
    if(msg.charAt(i) == ','){
      subStrings.push_back(msg.substring(j,i));
      j = i+1;
    }
  }
  subStrings.push_back(msg.substring(j,msg.length())); //to grab the last value of the string
  return subStrings;
}

 

 

 

 

Leave a comment

Please note: comments must be approved before they are published.